import swarm.Selector;) f% b: r: ]1 ^. w4 t4 h. d8 \. j4 O
% i8 U" ?. I) i3 _+ l- Ypublic class SwarmUtils {2 j' @8 v, Y/ Z$ s
public static Selector getSelector(String name, String method) {0 i. i* U) [5 z# {2 u
Selector sel;
" M% N) L2 c) a$ T3 R try {
5 F! p! ^) ]6 W1 l sel = new Selector(Class.forName(name), method, false);+ u: @$ H: A/ C6 W! O
} catch (Exception e) {
/ B: p4 J- t ] System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- h2 D4 J7 |4 ?- k* h! K( G
System.err.println(name + "." + method + " returns " + e.getMessage());
* a2 X d8 H# g& i System.err.println("The process will be terminated.");
, f5 v8 V) k2 O! Y- z; i! K' U8 y System.exit(1);
3 u) _) f7 `5 t+ _* z( C8 ^: Z0 P9 n return null;
+ Z' P5 e% @3 ]. y1 V% O }, ^' v5 H6 g& }* h% x
return sel;
# g5 k6 {9 d/ M: Y) J( G0 o }
$ S( K8 E7 ~! x! x: Q
" i: e- H# t1 g) R public static Selector getSelector(Object obj, String method) {6 J( \( f, V, q# z7 D
Selector sel;+ Z1 v* V7 E6 O& t# o6 B
try {
4 E8 e/ b1 w2 `: h' Y/ o& G9 e sel = new Selector(obj.getClass(), method, false);
; m, T5 T9 [' C- U } catch (Exception e) {
9 x5 r+ Y9 S' h6 b% C- F System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 \" U2 e( P J$ n2 J3 p: Y8 B6 a + (obj.getClass()).getName() + ".");
8 W0 u$ d1 ^8 V System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 N; E" A7 C% Z) O) O z; \
System.err.println("The process will be terminated.");
6 ^3 T- S& Z5 y* e; d& |2 t) e System.exit(1);( x/ E9 o5 G6 e: B3 M* s* c
return null;4 ~/ O. W5 _8 l) M- k- o y, \
}
5 h3 m* z5 r7 D6 r( y! S- h# } return sel;
( U+ |$ E, v. O) s1 ], I7 c. \! S }, X+ v( n3 A0 x: i% J# T0 |" t
} |