import swarm.Selector;
: j% _0 U4 X/ N, z
W1 v& j1 ~- P) i' Gpublic class SwarmUtils {/ R7 b, ^' d: \2 q. B0 f
public static Selector getSelector(String name, String method) {
2 V+ D1 ? D3 s0 X Selector sel;2 |& J3 m. H6 C7 W+ B/ N( f: N
try {6 y, h9 I; c4 k! @9 _
sel = new Selector(Class.forName(name), method, false); N' ~$ c! q* N
} catch (Exception e) {
* D( R* E+ k& t! e! P6 K( Y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* X+ g1 }+ R3 j; P. K$ q- g( L: N# r4 }
System.err.println(name + "." + method + " returns " + e.getMessage());
; V6 x z3 _3 P9 t2 o; a8 @5 f6 q System.err.println("The process will be terminated.");
" S+ [4 c+ N5 m, X* K System.exit(1);2 ^8 p8 p1 V& |9 d
return null;- C# F; g' B/ D$ X
}
. }- S: ~; ?1 m! F% h return sel;
8 z: j; N; @, D$ [- ?) i8 ^ }; N# e8 ?& h+ V8 f( H" Q1 u+ S
" X$ e/ Y- H% M* ~
public static Selector getSelector(Object obj, String method) {
& N! R3 v- ?/ X7 _ Selector sel;8 k# {1 Q# v2 a x% u" Z& i/ T
try {
9 y8 R: w. l' H+ `9 ~ sel = new Selector(obj.getClass(), method, false);, B/ Z& p. s+ g* L q& k2 H
} catch (Exception e) {
; J* Y1 M( H! _" X3 [8 U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: W1 {8 D* H" }+ @2 f + (obj.getClass()).getName() + ".");
) y8 [9 ?& X4 K' ~3 K; L System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 n! ~1 ]5 S9 Q k6 F( J System.err.println("The process will be terminated.");
) z* p; ^" ~% |0 W3 l" n& p System.exit(1);3 I1 {; F- V) O8 H# J
return null;/ `( f0 e# Y! b
}
, ]1 }) E8 g. f8 ] return sel;; W9 d# M ^, y
}
/ I6 d1 ^$ j* L* S+ z0 |/ U} |