import swarm.Selector;
5 `4 A+ ], x7 E6 v/ f' @& }. Z0 U" @
public class SwarmUtils {( d8 Y7 ]+ O, @- j% j0 `' l4 N
public static Selector getSelector(String name, String method) {$ k U% ?% f, I7 [/ s
Selector sel;
3 T( z- A) c* | J( y try {) ^, n5 ?# N1 _( p( H1 {/ V/ q
sel = new Selector(Class.forName(name), method, false);
7 B; D7 E9 C; T2 M, r) P- w- {% ? } catch (Exception e) {
' g. u0 O" {7 N- x System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- F, s0 L% P6 V' c. D
System.err.println(name + "." + method + " returns " + e.getMessage());( ]2 N2 M7 F2 I* `
System.err.println("The process will be terminated.");9 [. u6 d: ]2 t% r
System.exit(1);7 O! O- m( M& [1 E1 ]
return null;
9 h% m- n1 x; P; B+ c/ s' p }
3 U- z3 W" N) |' b8 t& I return sel;
6 s# ?/ i2 w0 B0 f. L7 V/ c2 x }
1 R% s, L( g, |1 _
* `8 M% u) P) p2 p public static Selector getSelector(Object obj, String method) {
$ V4 N5 F' w+ a4 t& U% M: p Selector sel;# X) m. b" h! J: \
try {
1 A+ a8 \) }$ m1 J0 u+ z sel = new Selector(obj.getClass(), method, false);
" j" u% ~( Y3 G } catch (Exception e) {3 a0 K* N! x4 z) K; F
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- T' ~/ N: H' O0 i + (obj.getClass()).getName() + ".");
' P. ?1 e9 N" g6 |$ p System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());3 |1 Y9 `6 i* S, L6 a
System.err.println("The process will be terminated.");* \/ d' l, q0 f* B2 ~
System.exit(1);1 M( m* O# `( M; d6 B1 \
return null;, N1 }* @& K% e0 b) w& l) z% i/ e/ C
}% V! @' ]* G" _" C }& Q2 Y
return sel;
4 V0 L7 v7 |1 J$ ] }
/ d5 Q) {; i; J2 X1 d( [} |