import swarm.Selector;
& Q. ~" ~$ S1 n; z) Z
) O& p1 D. T: h" spublic class SwarmUtils {! E: J6 H/ m/ e9 [
public static Selector getSelector(String name, String method) {4 ?" V) a+ O: {; W2 j
Selector sel;
% `; n( `9 m- x4 K, l* U2 E _. ~ try {* c, e- m" I4 B0 L
sel = new Selector(Class.forName(name), method, false);
6 Q, y6 ~% a/ ^7 t: o- K' j7 K } catch (Exception e) {& A+ G- J5 C+ N7 C
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 Y$ i2 ?6 @6 ^0 h( E/ P4 I
System.err.println(name + "." + method + " returns " + e.getMessage());7 j1 Z! z4 l1 \+ R( {2 D
System.err.println("The process will be terminated.");
$ L$ q$ S' f9 g. \* N System.exit(1);
" H9 T g N/ u! B% U3 u: n% y$ p5 @5 m return null;; _. C7 w6 E! }* W% Q0 Q
}
$ h$ ?' k; E0 J% z+ M* v return sel;7 [ z2 k" O, W5 d
}: h; }) t% m2 \8 ]7 N E! q
7 d4 S$ x: P( I( f; c9 v# W public static Selector getSelector(Object obj, String method) { ]1 ]9 U( y2 |0 s2 n& Q
Selector sel;
6 ]5 v4 E9 R7 }0 R) Z/ N try {- X4 J. G8 S- K
sel = new Selector(obj.getClass(), method, false);
2 S& y. o* O; G" |2 I; @ } catch (Exception e) {
, O0 A* w! i- m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! ~; I8 q9 w. A' n2 H! }
+ (obj.getClass()).getName() + ".");. L. a2 [/ c/ B; D
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ X7 U; l4 F" D8 b1 @3 P( P0 f
System.err.println("The process will be terminated.");+ y: w( T7 V) h8 `7 I% ]
System.exit(1);
+ V+ E: k# L t4 f1 [ return null;
( L; G2 G! I5 G: e }
a; n8 I4 T! S! N) N return sel;
; r% q9 a" ]$ [' F! r7 Z% h; L" G+ z }0 o1 V2 ^4 [; h% H- ]
} |