import swarm.Selector;2 C( t8 \) ~5 H
( y+ b' F4 R$ l opublic class SwarmUtils {1 p' L; \, L' c# v1 B$ z
public static Selector getSelector(String name, String method) {, A/ z2 [# h. \& a9 t
Selector sel;
2 N5 y: i" P; V2 H- _ try {
' _$ a- f) V% z$ Y sel = new Selector(Class.forName(name), method, false);
8 y- L/ q3 V& _- _ } catch (Exception e) {
- s% w$ h# A6 M* L, R System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 P9 X% m( w! ?
System.err.println(name + "." + method + " returns " + e.getMessage());" G/ B" b8 s+ Z0 S8 P: V/ s
System.err.println("The process will be terminated.");
' n- U6 e! u$ S& S& l System.exit(1);
! ^9 C$ [: _3 G/ i# |2 c _ return null;3 n. i7 D3 V- _8 s% Q9 x/ w
}% N* ]% Y3 A* T5 o( ?
return sel;! X; P) S2 l. B8 ^
}2 I: Q6 |+ R2 r( N5 a1 x* \
. R9 W0 j* c, R
public static Selector getSelector(Object obj, String method) {
( H, @- t1 w) c% l( p7 S- ?1 }& b Selector sel;
$ n% |* u; s! i- J. H0 V( `9 w try {
2 Y: ~! E% q6 H, } sel = new Selector(obj.getClass(), method, false);0 }. C7 p2 K2 Q. `
} catch (Exception e) {& r" n, g* U% d0 y2 `
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 H2 r! j1 u: @$ N& J0 ]
+ (obj.getClass()).getName() + ".");
; L1 S! t; X) l% L2 x/ B System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
; |" { O$ Z) n/ @ System.err.println("The process will be terminated.");. f1 ^% S, `" X, ]3 |! U4 o
System.exit(1);
/ I+ F q7 [1 ? return null;0 f Z- p( h* p# T; m4 b
}
& j7 n+ R8 b2 c, O return sel;0 |( V, n: X7 q
}3 B8 a! w7 g6 ~
} |