import swarm.Selector;
# N- ~" ^, O% ^& A% a5 i- F
0 C9 C" ]" A7 Vpublic class SwarmUtils {
, @9 E( e% O6 h0 n public static Selector getSelector(String name, String method) {
% p& I6 q" S4 \# }! B Selector sel;
X: p, r3 B- c. F+ z try {
# t- |8 T, b& O/ D% U) ~! f sel = new Selector(Class.forName(name), method, false);" R! e/ ]+ W) _* n1 F7 q
} catch (Exception e) {1 k: U0 m" {4 T, t& [
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; k- w% |3 }, t
System.err.println(name + "." + method + " returns " + e.getMessage());
( Y6 U. A4 w' C. n0 A System.err.println("The process will be terminated.");
/ r* O; W5 e6 q A System.exit(1);2 j ]; j4 A" B$ j; @
return null;1 { y9 ]4 ~% C- a: j4 v: w: V1 u
}" M$ G6 v9 [8 e2 s( |; `
return sel;/ f* O5 H2 W$ O0 x: P
}: y# F1 V) b1 G3 L" z
/ N- x+ I/ a5 y$ ~
public static Selector getSelector(Object obj, String method) {
! J( a4 C% Q5 i/ a! w: b Selector sel;2 k* F- m# U9 k1 z. R, I K
try {
8 J2 U% b& r) m" [+ \ sel = new Selector(obj.getClass(), method, false);
! I! z4 n$ P. F& E5 q } catch (Exception e) {+ N$ r7 z$ L% e1 L i
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ L3 O# T0 x* z8 J
+ (obj.getClass()).getName() + ".");
9 c6 l! q! j! [' y' z& y1 ?# R' I4 V: J& y System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( y C2 r4 r1 Y1 @- L
System.err.println("The process will be terminated.");
# C) ~" Z6 V, y$ R System.exit(1);! ~" N3 t ~/ k8 x
return null;
1 b7 T# q$ N8 i6 T' J }
5 Z) |0 O+ H, A4 n) c" `& l return sel;
]0 D- U6 n. T% Y) U }
2 o" Q9 c1 @5 _} |