import swarm.Selector;" J( ~ m4 z2 |& r$ n( P/ s6 F% G
4 D4 L7 }9 O2 g, a
public class SwarmUtils {: i1 N. _/ f( V! N
public static Selector getSelector(String name, String method) { f G9 y D' m4 p) R5 F, ^
Selector sel;% ^3 E2 ^, ~( y5 G3 p
try {, z% }0 L. f+ E2 K6 x" W
sel = new Selector(Class.forName(name), method, false);3 ]4 A5 e- {2 ^" M7 w x" i6 v
} catch (Exception e) {4 V+ p+ d* [5 B: J. W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; M W# ?6 H( _) z3 i5 t" \
System.err.println(name + "." + method + " returns " + e.getMessage());; n, b- R& T+ S! n" t
System.err.println("The process will be terminated.");
$ i; E% E( s4 m* B$ P9 i, H# v System.exit(1);) _6 P; Z- o; L
return null;. V* Z: ]) M" w% s9 L
}: q s0 z2 X6 A
return sel;- T: F& v+ D+ K6 r/ Y- L+ }
}
) d9 b) e4 l" o, `# @8 z: a5 Y S
( L! l4 Z! l* z) e# r$ h7 K6 f- J public static Selector getSelector(Object obj, String method) {
0 B" e: \8 P$ h f& p, h( _ Selector sel;
% o' ]2 T2 u, y) F4 x* O* b: `! F try {8 e, U5 E, q2 E) f
sel = new Selector(obj.getClass(), method, false);
, ~7 s- f- j# u } catch (Exception e) {. i$ t8 G% f1 y( R% V. r7 x' m
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# r1 @8 l4 a8 J: U4 }
+ (obj.getClass()).getName() + ".");
6 d0 e! f% y$ T! G* j System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. t Y0 h2 b# v
System.err.println("The process will be terminated.");
, F8 ^6 i2 l4 I# H! v( f System.exit(1);
( C- j% r* l L1 p* D$ W+ t return null;$ D% p0 k- _5 y$ Y2 ]9 {
}
) A n, A+ b3 q2 f. ]4 e. l1 p return sel;' L4 `6 @+ o) q$ Q6 E, s# R0 F
}" {2 N0 X: k4 w) @, ~# _+ ?- s; Q" h! M
} |