import swarm.Selector;6 M" A; O% ]$ C; v' e2 |& q6 Q
1 O0 L9 I$ Y) C$ L* K6 n6 mpublic class SwarmUtils {# r- L- Y( q- G
public static Selector getSelector(String name, String method) {6 u5 t, h4 n, x c
Selector sel;1 H9 |% z# E6 x8 d
try {
1 R! Q( V4 r5 r3 ?5 T# m! E sel = new Selector(Class.forName(name), method, false);& X% y* X8 a5 o& F. K( o2 ~7 M+ |9 |' P
} catch (Exception e) {- w5 R9 r& S! d9 v9 k
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" X+ q( a0 s g System.err.println(name + "." + method + " returns " + e.getMessage());2 C9 `$ j; ~8 |3 F+ h0 b$ c( g
System.err.println("The process will be terminated.");
; W+ o+ x9 G2 O+ u6 p% _, m: }1 S System.exit(1);! u5 [3 x" a' p5 g1 A: ?! L# O" @
return null;( B1 a( E# C: b6 P; u1 W
}: z( T1 \# L7 T/ Y4 T% J. _
return sel;
) ~: p- z, u' j3 b& E }1 g4 z" _% _- n* C3 @
* m0 t- M3 e6 z) `' R
public static Selector getSelector(Object obj, String method) {3 t( D w8 ^- e! W, B' d
Selector sel;6 Q$ p) p6 y; Y; ]8 C
try {# X: H7 d% ~: w4 _
sel = new Selector(obj.getClass(), method, false);# ^6 ~" E Q' Q; p* K
} catch (Exception e) {2 L& w4 b/ o* Z" m; d. O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" M) U+ v* }3 `" S: n + (obj.getClass()).getName() + ".");3 F& w/ U# g- V5 e4 R* }! h1 @
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 M6 ?( p7 r2 a7 A j9 f! G System.err.println("The process will be terminated.");' I `6 C, t* A7 @6 C
System.exit(1);. L' m, L$ i6 T" h1 n7 k
return null;
4 v* F! `1 {+ Y! ] }4 B9 `9 g( n# W- j4 G
return sel;1 W: p* |/ C) e- {3 G' }. m
}
" @% B0 Y$ [( Z# j* \+ b! q1 u& B} |