import swarm.Selector;5 z* C8 p G3 t: F- f
+ W$ c" d1 L! r" j
public class SwarmUtils {* w( x8 Z c' V5 R! q) Y
public static Selector getSelector(String name, String method) {
, m9 [- {9 j7 t3 v1 o Selector sel;. u% U; I6 C% H" T+ _# K& E
try {7 M, i' i! \: @: G2 @( ]* s% C0 S
sel = new Selector(Class.forName(name), method, false);
6 e1 I0 V/ U$ B) W } catch (Exception e) {8 \7 V! C& l6 X. F4 A P# D' k
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 Q5 k# O2 E1 @2 g) \, @/ I
System.err.println(name + "." + method + " returns " + e.getMessage());
' m Z6 \, P' [3 r) K" K( [( R System.err.println("The process will be terminated.");4 ?! T; ]( H4 _7 j6 l
System.exit(1);! W" u. J8 U' L# L Q8 M" G
return null;
* j: z5 \ n! ? }
$ r2 }& s! V2 }" w" w8 x! ]7 G return sel;( F7 o$ [. P- _/ t* }4 ]( G
}, G$ R B/ ]) v/ Z) L6 A
* a# M% }+ F+ [6 o
public static Selector getSelector(Object obj, String method) {0 H; b5 b3 Y0 V/ h* @$ _* x
Selector sel;
) i# k, s" N" z9 A try {
' w2 [, [8 q' k7 }' S sel = new Selector(obj.getClass(), method, false);1 t: c9 m' B) Z6 K! Z# K6 }+ L
} catch (Exception e) {
# ], a- r7 N+ c& T7 A" B+ Q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 H& i0 I4 Z: L5 n1 Y# y: ^ + (obj.getClass()).getName() + ".");
! d6 N4 j7 O0 @ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, ~' p( Q( v* s) s
System.err.println("The process will be terminated.");$ q$ f: p+ m2 ?! J9 S+ v
System.exit(1);
" F& l# a! b, E, D. p5 L8 b return null;: L. k/ L$ S3 y2 W! \/ p+ H
}
& M, g8 s3 ^0 l' d5 u return sel;* ?2 s: f. n$ Y8 {+ n1 U5 y2 r
}
. E2 }/ ~! I6 g# Q, J0 F1 W} |