import swarm.Selector;
4 ~5 ^) R/ Y# y) Z# U
0 l' L+ e) {9 m/ a7 }* q7 [public class SwarmUtils {
% Y2 K% ?7 e6 j public static Selector getSelector(String name, String method) {* N( ?! L* G0 D
Selector sel;
/ |- A( J/ A. z; ^7 y try {7 C5 X1 d& t) }" ^/ }% i
sel = new Selector(Class.forName(name), method, false);
$ L3 L3 J, u) P4 E# h3 o l } catch (Exception e) {
# a( V8 f, U4 g: R/ r System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
+ ~9 w1 \" U) w. h System.err.println(name + "." + method + " returns " + e.getMessage());8 u3 |" H# N& Y( R; X
System.err.println("The process will be terminated.");) s/ c7 ^ n1 f6 L- G" X4 G8 j
System.exit(1);
3 Y5 O5 Y- S" r" h$ {% D: o& m return null;3 l: w- J& o1 r$ u% f! [
}, i; k, ?# H% c4 N% h
return sel;
: d) g; Z8 s- j; s }( y4 y) V+ y- ?, V+ i
( B1 \1 e5 `( k' ?% m! u1 t. v2 J( c0 y
public static Selector getSelector(Object obj, String method) {- H. J. h+ p6 d3 U8 @5 r d' o
Selector sel;
% Y2 [6 f! D! P# b try {
; s6 U r" d7 l- Z I% v( u sel = new Selector(obj.getClass(), method, false);
/ Z* d' p! v$ f j- ~ C6 J# u } catch (Exception e) {
?1 M1 ]5 l e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( m% e2 }5 S7 _ + (obj.getClass()).getName() + ".");
. Q5 x- I" w- `% N {7 P& p System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());- y7 n' f- [3 r4 h* b
System.err.println("The process will be terminated.");- H, {8 \' j9 v5 \; F! K' W
System.exit(1);" o. V& q: M% y5 }. S p G' z; w
return null;
; o" J9 w. z4 I0 n. }& n& p }
: I4 u. x1 i; M8 _0 h3 v( Y& o return sel;
- E6 g" f& L, i, {" r/ o }
% F! a% j; r3 \- K, g} |