import swarm.Selector;! @- y+ X+ x# r" a& E7 T4 g. x; A
3 t" n) F3 ?% l5 J, K y. Ppublic class SwarmUtils {
; \; i* L- A3 I1 R1 R1 j( z public static Selector getSelector(String name, String method) {+ D$ m- @' M) E# |
Selector sel;1 b/ p7 h- y2 G" a8 c
try {5 i5 m$ }4 N8 X2 X% l' i
sel = new Selector(Class.forName(name), method, false);% v2 _5 W$ b& T& a- p
} catch (Exception e) {
1 r# }1 @1 e8 O- C, n F: X System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" G( z! X, P7 P System.err.println(name + "." + method + " returns " + e.getMessage());
- Q7 D/ l. x* B( N0 _ System.err.println("The process will be terminated.");' B% b5 P8 b+ B3 G! b7 h! z# G
System.exit(1);
- V& I" W& a5 _ d5 X return null;
3 e4 D( C6 l, ?, V }& T- T& S4 I, b" b6 u: B6 {
return sel;' j, }& W/ Y! x0 i3 s/ B1 N
}, D% g0 h* }9 k d3 [
q/ x3 E) D6 E+ r
public static Selector getSelector(Object obj, String method) {0 Z& i4 ]' N% j5 a% d" O
Selector sel;. l; Y% @ _' W @" R6 A
try {/ k6 k5 o6 E+ F0 L! q
sel = new Selector(obj.getClass(), method, false);8 ?4 ?( W. |+ m4 d& b: G N q
} catch (Exception e) {6 Y& U, l3 B* l# f; l6 z+ Q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ V' H1 [/ c7 `* t( r2 O + (obj.getClass()).getName() + ".");! f: A8 u. N+ w% E) d0 W
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ {$ {8 \; a, m! @ System.err.println("The process will be terminated.");
1 I5 H4 v0 w$ y/ }, c3 P# D5 k System.exit(1);5 Z& [ h* f8 C s; j
return null;. w( b# g9 ?: J+ g
}
; O ]( ]% I8 t7 p S+ k return sel; o) W6 S$ A; [2 N9 ]5 k! H
}0 Z) t/ r; b) r2 H( |+ n% r; G! R
} |