import swarm.Selector;
|0 o1 N$ x. J! P6 W- W1 T9 P6 S. Y- O* `
public class SwarmUtils {9 z z. l! {: F% ~ u. i* b, J6 V) ]
public static Selector getSelector(String name, String method) {% K3 | Q- r/ \: t! v& ^
Selector sel;. R+ Z( \1 p7 o) L; {+ x+ R9 \
try {
. t8 K; f8 h) W3 X# U- u* L7 q; _ sel = new Selector(Class.forName(name), method, false);
3 W7 e8 A2 j( \0 X4 Z# x } catch (Exception e) {
! q+ O* \( d x5 ?5 \2 D0 h" A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* a; C2 U5 B8 v2 @9 Q
System.err.println(name + "." + method + " returns " + e.getMessage());8 _: n! W" ^1 B2 V
System.err.println("The process will be terminated.");
3 h8 P& J5 q: E System.exit(1);
, h7 D0 T- y8 X1 {) C return null;2 F Q b: |. W( U/ _- Q6 Y! n( e6 L& e
}
) H$ @6 F; S9 j$ ?7 Q" q4 }, U return sel;* ~9 k( j& k9 ^5 m8 x; K
}
" i+ V8 a* `0 Z7 E$ ?4 ?. R, i( E! h8 M8 Y+ ]7 H* K0 Y+ ^! P! c: j
public static Selector getSelector(Object obj, String method) {
, l: @, k5 V3 V3 S0 x( [& t l% J Selector sel;' ~0 _; f& D( x$ T
try {
7 C; e. e8 s( \# K% Q0 h sel = new Selector(obj.getClass(), method, false);1 V: g7 t% k6 ?' A& U# {- k
} catch (Exception e) {
8 L- N0 d' B! ^ r1 \ G System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% E8 }: F& R$ P + (obj.getClass()).getName() + ".");
# _1 c7 w% Z T( }+ C; _ k v System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ ]) z9 N# o' z0 _8 v ?" W System.err.println("The process will be terminated.");! ]) p7 c X3 _8 j S- p2 M6 g
System.exit(1);4 q+ [+ Q) U/ `& X5 W
return null;0 s. v. i1 M3 {, I' _9 R
}4 V" D, U4 i+ ?2 S* m
return sel;' _$ B* p# A) L0 e! p
}1 s I- J: R8 s0 n# l; N2 V6 @, {( ~
} |