import swarm.Selector;
" o; a4 q6 w! ]. u4 k1 r
& q! Z6 b$ W, a% H, Vpublic class SwarmUtils {7 j& [& S" q/ X* U, Q# l e, J* C
public static Selector getSelector(String name, String method) {
* I1 f0 p9 C$ h* j( B' ^3 c c Selector sel;) Z3 Q) N* O% ~6 ]" ^. y
try {, B9 F: u0 c; ] z: Q- Z2 O
sel = new Selector(Class.forName(name), method, false); Y- o; `3 s @6 j1 m& _# N' c3 a
} catch (Exception e) {2 O9 d! y' t9 W$ j' B2 C9 e2 _
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* f4 X4 A7 E M5 F5 s1 n
System.err.println(name + "." + method + " returns " + e.getMessage());# J, d, `2 `3 T) N
System.err.println("The process will be terminated.");
) `# u/ a4 Q6 j; R8 j% r System.exit(1);& \6 U& T9 Q4 d
return null;; Z) r. O) c( U$ ]
}
: A% S1 G- Y& f8 { return sel;
# p$ _; I% A" G! l( U" j }
+ B/ ?, r1 N0 q5 Y
* z& m! x. N7 v$ n* s9 T5 u public static Selector getSelector(Object obj, String method) {
t5 b: ^$ ]$ V7 l# @$ B3 |7 v- O Selector sel;. R+ r1 k. @5 L8 n
try {
/ x8 @5 b; p7 }! v) r2 y' { sel = new Selector(obj.getClass(), method, false);
( ?# |4 B" q; k1 G& ` } catch (Exception e) {
/ Z8 \2 V% B: S8 z _ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
2 }; g/ [4 F q" G7 w + (obj.getClass()).getName() + ".");) s% a( ^5 w- B! Q( S
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* T8 ]$ e0 `2 F7 B. |, c+ N System.err.println("The process will be terminated.");; N0 ] d K5 V( v. Q3 B F
System.exit(1);' V! \$ i" W: R
return null;+ U% [- G/ `6 W, ] ]% z0 N
}
9 ~" ^0 x5 ?4 m8 D return sel;
# y# x! @+ o3 D2 G$ l4 L' m }$ C# D9 W/ K0 E; b; @$ d! c
} |