import swarm.Selector;
$ r3 d! P5 X9 n- h3 h+ _5 O$ C. I1 M' w3 n) Y
public class SwarmUtils {
1 h$ K! i/ |- \ public static Selector getSelector(String name, String method) {. w' }% K& L/ N0 w
Selector sel;$ R' R7 B' E5 i- Z* }
try {+ V. a; R- N/ }$ \
sel = new Selector(Class.forName(name), method, false);" q2 G: x+ S5 M, @- U! e3 j+ m& x
} catch (Exception e) {$ F3 E! z; Q6 E. F" ^. ^: A
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 p& @. a5 Q( ?' t( b9 U+ A
System.err.println(name + "." + method + " returns " + e.getMessage()); o E# ?( Y4 B4 B8 y
System.err.println("The process will be terminated.");0 z' [3 L0 C8 r( a5 z. v! H0 C
System.exit(1);
7 n5 s8 b" L) D2 ]* h) ]! I4 M6 t return null;
) t1 p2 I, |' \7 B" S$ V7 Z9 h9 b: ? }
/ g/ ? @# z" T! r return sel;. b: n3 y+ i# n3 _7 Q4 F" B. ]
}
9 L9 k7 d6 }' q9 m- u* N7 ?; j. q* T7 D9 j. _7 I8 t2 M1 N+ u& m2 j
public static Selector getSelector(Object obj, String method) {( N. `! b+ Y3 c& H7 P
Selector sel;
, J- z8 v1 G: W8 Q! m try {! ?# {) W j1 n/ X0 A6 g
sel = new Selector(obj.getClass(), method, false);
/ F1 i& Q% ?- p+ W3 s8 G$ @- } } catch (Exception e) {# a: K/ m9 c/ W2 ?! A8 d
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ D' f3 T* j; ~! Q4 ]; S# Q& H$ i
+ (obj.getClass()).getName() + ".");
) s3 N0 T* ]* R) k R2 ]' h System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* B3 ~* K2 O2 P: l4 ^
System.err.println("The process will be terminated.");
* N. s9 X$ V/ F, T0 y" y+ w' R System.exit(1);" O6 m: S- w/ v2 U8 A+ Z' T" n. O: g2 E
return null;# J( F8 P' O2 k% j5 g
}4 O- ?4 A+ t, ]3 [6 D
return sel;& F1 W5 U A, C' j2 x' O b
}. M% p4 G: K( t3 |- f) w, [2 d9 k
} |