import swarm.Selector;, q5 B {# z# k: q# s
; p" ]& M7 ?, T% H& p3 [3 {
public class SwarmUtils { {8 s* i. a7 i. I6 B2 m" i4 Q& C
public static Selector getSelector(String name, String method) {
$ w8 p1 |+ z; b' c2 G/ A( y Selector sel;
& X0 W- {6 z( x5 P- O- c$ ?$ R: g: i# [ try {1 l0 h, p. d- m& q! x) |" r, }. K
sel = new Selector(Class.forName(name), method, false);' y9 q, @" V1 y R
} catch (Exception e) { f. h0 F* ^! c2 p8 J; }8 j
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& } a! @5 G+ ?8 ?( W
System.err.println(name + "." + method + " returns " + e.getMessage());# z- y$ k) a {) s5 w& \: m
System.err.println("The process will be terminated.");8 ? F" b! L) {3 ] g& Y" ]2 Q
System.exit(1);
! Z0 e8 ~! R4 U0 [ return null;* w2 Y) ?. W4 A3 r# I
}
' [* q' `4 g: ?" { return sel;8 q- H3 y& k; e
}
& l( a$ R6 r6 h, r5 w8 c- Q
3 l) |& @) X( X. H public static Selector getSelector(Object obj, String method) {% o8 u/ ~* {6 `
Selector sel;. d' t& d1 E) ~9 z" Z0 m
try {
5 f- r7 y- l D/ N! y1 I sel = new Selector(obj.getClass(), method, false);" N) _. v) t$ ~. T- a9 T1 _- R" t
} catch (Exception e) {2 J g! l! a P* C" U2 z( n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "( ~: i* {9 {+ U" u- k
+ (obj.getClass()).getName() + ".");
& R- e' L: M! K! K6 F/ R System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" ?3 D x, R" B9 a# Y$ h T! w
System.err.println("The process will be terminated.");7 z- u3 j4 A- w& e( _
System.exit(1);
6 b! Y3 ~# w- ^ return null;: R7 ~4 u( ~. E( W1 }( O5 W$ A( I
}
j9 Q" M% t5 U) _4 K; B. H3 ]& | return sel;
q5 v9 ~" x& S4 ?! m3 g- D" x }
' X8 }& r* Z$ }: w5 k w$ q) n} |