import swarm.Selector;
3 i% F% H/ ^. f! ?' u! b
" u& Z( A& @) p. Gpublic class SwarmUtils {1 A4 m5 h& q6 Z1 t$ F( ?% ~4 p& A
public static Selector getSelector(String name, String method) {
/ e- }5 R. {& E7 o% c# F Selector sel;
5 w5 \+ {5 J/ Y! X& t try {% N* j" C/ @3 p0 x3 D1 \7 P
sel = new Selector(Class.forName(name), method, false);" a0 `% w+ G. ?) [0 p% F
} catch (Exception e) {
& \. g" ~% d, w, j% ^4 B0 W System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");8 D* |2 C" f. X/ T
System.err.println(name + "." + method + " returns " + e.getMessage());) X' i L2 q& Z6 V$ F$ F
System.err.println("The process will be terminated.");, H7 ^3 f0 U7 w( ?! O6 z
System.exit(1);1 |" Y& p$ K$ ?
return null;# f5 `, B% j: Q) q/ e8 K
}
D1 A+ M, ^# O% T, W return sel;
2 c, n% r) }" n# z/ L# \3 Y) c* w }5 y1 ]; H3 `" z# Y- ?
, S! {. e1 c3 U& N, a% c6 g1 x
public static Selector getSelector(Object obj, String method) {; A4 z/ L0 A6 P* O2 R4 e! ~/ f9 D" T
Selector sel;1 \1 j# h& i% l+ c' R1 j9 ^
try {
9 S' {$ j, A- w$ h sel = new Selector(obj.getClass(), method, false);% R: e9 H7 h% v% O- Y _
} catch (Exception e) {
" F3 w0 U( {, F+ I" e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 _1 i0 G8 [3 Y1 E) R2 d + (obj.getClass()).getName() + ".");/ P& j3 t8 L+ S3 X, H' m3 d* T+ S5 H
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; V7 c& b% s( O6 m0 j" T- ~
System.err.println("The process will be terminated.");
' Z7 l9 I% @# \$ _9 J System.exit(1);
, K% [# q: y/ ]/ V& [2 s2 @ return null;$ i: O* h" R3 R, t
}
9 o8 V. R& Q, Y0 s( [" q( D return sel;; J6 D" d7 A3 I4 H7 B
}
8 E$ k+ x9 ^& A+ h$ n} |