import swarm.Selector;4 c5 a% p2 `* }( @
3 T. k1 D9 q6 |, r1 T' I4 [( O
public class SwarmUtils {7 V& R: Y' \/ u9 T
public static Selector getSelector(String name, String method) {
, T m' C* }* |' N; L0 e Selector sel;8 y7 T i% U# E2 p, w; Q/ m8 L# n
try {4 _9 c+ f, f% M: S
sel = new Selector(Class.forName(name), method, false);
. M3 w9 A7 x6 O% d$ K } catch (Exception e) {: j8 n4 }/ c& q k
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
+ I, h; e* P4 s7 C# @- X& R' ? System.err.println(name + "." + method + " returns " + e.getMessage());
# L# Q' ?7 P7 i% @5 {7 Y System.err.println("The process will be terminated.");
) O; W3 z% P0 N% }$ [ System.exit(1);" |, W0 X+ s8 a) Y9 C( J
return null;
# g5 y6 P/ _( }( P3 g }' N9 x; ?, U# [& P1 i, P# i
return sel;
S& I; z2 R/ t }. _9 i/ F7 K8 u, t& Q( m
6 s J9 `3 ]2 G! h! e, e0 q public static Selector getSelector(Object obj, String method) {
T+ ]" n, U- ~: d0 E; |3 c; P Selector sel;
$ k0 N& M. z' ^ try {# @' ^' l8 }# s+ f% |/ Y$ \
sel = new Selector(obj.getClass(), method, false);' y6 W4 q) \) c
} catch (Exception e) {4 e: D( }1 ^; w/ a* W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' F: |7 ~. w4 w7 M: e' F( W% B
+ (obj.getClass()).getName() + ".");7 ]6 _* a5 Q( [9 V
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, A2 C, ~4 I5 K1 l3 \8 p System.err.println("The process will be terminated.");8 r$ b4 ~( i) k
System.exit(1);
& Z. A: C3 x; }5 z' ~# f% { return null;' \6 u: {- s `- F* C
}
+ a( h* E7 X- G9 X* l+ [" T: v return sel;
2 g$ ~- @4 d1 ]2 ]% G8 w, Z6 ^; T, B }* I7 V! }& L# Y* X, a% L E
} |