import swarm.Selector;
& m: f. g+ g* r/ X1 Y
1 N! D7 e. R+ x! l) Ppublic class SwarmUtils {
8 ]5 ^: p' j" e5 L9 K public static Selector getSelector(String name, String method) {9 K- g$ \/ q' g7 \) \
Selector sel;
7 x6 }) m0 y+ \ try {
$ i( R5 ?& ]4 _% K sel = new Selector(Class.forName(name), method, false);
" T' O4 I9 c: l } catch (Exception e) {* B5 G0 A. L8 h. j
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
0 W8 t2 R" G0 }, e6 T System.err.println(name + "." + method + " returns " + e.getMessage());& w; p4 N9 _ h( ?" i0 V) N/ n# w
System.err.println("The process will be terminated.");
4 @+ }+ }# r0 W9 Z System.exit(1);
. O) x* f5 F9 w8 `) q return null;3 y: E* j3 Y9 p& o1 c
}* y# w; E! {4 w0 `. D4 ~
return sel;
5 H6 d5 @4 [' T }
H1 z' b* m$ @! h8 q6 B, i+ z1 Q u. Q* @( n: Y( Z7 v3 s
public static Selector getSelector(Object obj, String method) {& v' N; F+ @, k: c
Selector sel;% l/ ?. I2 v$ m. u. [' I
try {
6 o$ y* d/ R& b) e- D2 \ sel = new Selector(obj.getClass(), method, false);
" ~( m5 m: E. @: m' t! M6 j! I } catch (Exception e) {; w, D0 U, ^- a+ q. H i
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ [# l# g6 g2 m1 s: D J1 L
+ (obj.getClass()).getName() + ".");
4 h3 G# f1 a$ l- X$ O% E System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 I: U; u/ ?4 Y, b8 q c. J
System.err.println("The process will be terminated.");: |" A$ W( H% Q i) W
System.exit(1);
6 c+ u2 b% v8 }# F return null;
5 {% E! R# \+ N& e0 Q! f n }
) `( E2 E4 i$ F: `* j( a/ i( G! W" ^ return sel;0 c+ P% O1 J1 v" `) N: H$ `
}
& r+ u& c7 Q+ Z$ ~2 a} |