import swarm.Selector;1 C& ^0 c7 x3 ~; @
( }0 }1 h4 Q- t; P/ d% @& h# Z. W0 }
public class SwarmUtils {9 q- [# A) N9 u+ @2 H* V, _
public static Selector getSelector(String name, String method) {
; v% D; _/ c K$ g; J z$ p$ q2 O+ s Selector sel;9 [ l' v. h+ B3 p/ e g
try {
" e# |8 W- R1 Z, B3 P& ?, G sel = new Selector(Class.forName(name), method, false);0 s" t3 S2 M( J4 \0 _1 @# |
} catch (Exception e) {
1 I" p H! b" O System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; T" b9 V9 m, S( ~+ }% P
System.err.println(name + "." + method + " returns " + e.getMessage());( g$ Z# o, F/ U
System.err.println("The process will be terminated.");7 A& }8 q M7 _1 R: Q7 X
System.exit(1);
1 p5 B" A' e4 g5 |/ K3 ] return null;. C2 k" j: C- R0 J4 J) y. P5 u
}, X. J( w+ H: M: b( x/ n
return sel;2 o# K4 x2 F+ E6 F
}
; Z, l; |, k& ^% E3 p& h5 Q P( w$ h2 J
public static Selector getSelector(Object obj, String method) {
5 w: T3 h7 t2 S; r9 q3 N Selector sel;/ l/ r7 l/ P2 E; `+ A q5 X. l% W- u
try {1 w3 B6 G' |/ H& s
sel = new Selector(obj.getClass(), method, false);6 z2 [, b/ \2 t4 r& z0 T H
} catch (Exception e) {( f- i0 W- Z9 T0 d; Y ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 H5 ^: v# ^9 G: ~) o + (obj.getClass()).getName() + ".");
/ ?- a, |" D( _ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 c8 R2 W& n- n0 U0 D( I3 l
System.err.println("The process will be terminated.");. Y8 a5 X% L% r
System.exit(1);
; d8 p; b- f6 Y return null;
1 L* `8 ]( S9 q }
5 z/ J+ h* |/ p1 }9 u" i return sel;3 E ~ j1 z% n1 m" i: F
}
, R% e( s# t, q$ X% j} |