import swarm.Selector;
* t6 t' Q6 ?% j* L) M
5 l. A" p# F' {2 e( K8 gpublic class SwarmUtils {
+ p" J5 [* x4 l% c public static Selector getSelector(String name, String method) {
. V- |* N; h1 F% ] Selector sel;
5 j) T/ X3 Y: Z) l try {! f& [ t1 H2 k0 N& e
sel = new Selector(Class.forName(name), method, false);8 D- G! Z& h8 `# i
} catch (Exception e) {! H& j' L) ^" `* K; W0 y4 k
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( M! G9 U/ h1 ^) B3 ^ System.err.println(name + "." + method + " returns " + e.getMessage());: l8 m6 S/ y% E' V O/ {
System.err.println("The process will be terminated.");+ T7 c% ?. P9 u2 T( m- w' o) @8 q9 z
System.exit(1);
/ q, ^: S9 l1 @, @ return null;
- V" X/ D8 X9 W* Z& s9 T" g }' F3 S! r/ C% V+ ~# }
return sel;
9 `, l9 ]2 O" F' U* Y o( B }) V9 U) |" o( X6 C/ `
5 s: \5 i8 k/ o public static Selector getSelector(Object obj, String method) {. E Z, M2 S1 [, H% x% Q' _6 `
Selector sel;
) q& e+ ]( k1 @9 k try {
2 |* t7 a4 x1 U- p sel = new Selector(obj.getClass(), method, false);* g. f3 l% K+ G# @ \ t: B
} catch (Exception e) {
" ?* ^ O8 G% n6 y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 _9 U& o9 W$ O1 w% A
+ (obj.getClass()).getName() + ".");
! S6 t' C2 e; L0 ^* J/ M" L System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, p" n5 y5 w# z; `, a System.err.println("The process will be terminated.");% } }, J: N. Q( p: ~$ t. ?
System.exit(1);
" X |- q W( U/ X9 o7 a3 |! g return null;; p3 \2 S# v/ U0 p: E+ v& }
}
5 O; R% |7 e! D( f ^ return sel;
, R* @5 t* X6 c! K }
P1 @$ j$ L Q; Z5 w3 ]} |