import swarm.Selector;. a8 L+ T R' B' ?2 P& Y4 I
@3 b* U+ v/ A1 Y% |" P1 q
public class SwarmUtils {
* K/ v5 i5 T1 \- P8 y7 C4 m public static Selector getSelector(String name, String method) {% `6 A x1 N/ T/ l3 X, r1 B6 P/ Z
Selector sel;5 k# S) A/ z: I+ R
try {
. q! S" z5 ^) J+ t; v& v sel = new Selector(Class.forName(name), method, false);3 ?6 |2 r' Z. o2 h; ?
} catch (Exception e) {
0 E, y8 @9 t4 x6 {' _5 K System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 k+ q( g6 w" ?. S( E% v- @+ o& l
System.err.println(name + "." + method + " returns " + e.getMessage());8 w0 I9 D y9 Y1 u+ K; `' j
System.err.println("The process will be terminated.");
6 U, d8 d* R9 D/ F/ j System.exit(1);/ H0 U0 q. O. j% L7 t: ?
return null;
8 ^: F6 F" X; ^6 g8 G }
; o) V5 ?4 j& r# |$ m1 F return sel;# W9 e/ L/ T/ ~3 Z* U
}1 j( z: W; ]0 W/ @) I$ n
& q5 f. M0 Y' H( x' s$ F0 W, Q. a, K
public static Selector getSelector(Object obj, String method) {' p' m8 N; G% v5 V" i( t2 j! R
Selector sel;
O9 T( I6 p% F; |. k( u5 g try {8 Z, o/ v( ^: i' w
sel = new Selector(obj.getClass(), method, false);
' H% h/ ^+ b, w% s& W! N+ u0 U } catch (Exception e) {6 E. N5 y* S5 N& M6 @2 g) e
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' r2 w7 {8 S; @1 m7 L1 A6 F+ ^3 r9 c1 @
+ (obj.getClass()).getName() + ".");9 K3 L1 V7 e. E7 [ p
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());- f2 C7 _* l$ m1 J5 `4 V9 w9 v
System.err.println("The process will be terminated.");) U1 d6 h0 n, }* v' Z+ _$ E
System.exit(1);
: f6 K7 `1 s0 C/ G7 } return null;% r2 s+ T3 a$ ]+ ]; D" F! a2 {- _
}& ?8 u5 d% L1 h3 c' S3 C
return sel;( |+ M4 i6 r" Y7 V# Z3 i
}4 Q: H4 H5 n! }& V% l
} |