import swarm.Selector;7 J" j7 G* f+ F7 P. A: G4 d
9 V: {5 a% H( S! K' R9 ^public class SwarmUtils {
' B. V5 N6 B# n9 d0 t6 y" W+ S4 d public static Selector getSelector(String name, String method) {. s: U* M0 T; a
Selector sel;* ], n+ Z, k, O4 I5 M
try {
. C5 ?3 L& h4 J+ n sel = new Selector(Class.forName(name), method, false);; R8 i& q: K9 d3 ^2 B% }' a! X
} catch (Exception e) {
+ s- c( R( {; t, H System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 ~2 ?6 K5 x- ^5 f% ~
System.err.println(name + "." + method + " returns " + e.getMessage());
8 j( y8 m/ h* w System.err.println("The process will be terminated.");, Z. i, N2 {1 G ?% I0 y
System.exit(1);
. T" q4 b5 B; E+ L* i% }2 w return null; R- Z3 P6 C. r( D; U: X
}
' e, k1 s" e0 O; x return sel;
) f) A' N. \, X0 F' Z% {. Q0 h }
4 m) U& a8 N1 v% Q* {; q1 _3 Q7 p
6 P! ^9 q7 B1 u3 C$ J public static Selector getSelector(Object obj, String method) {& ^5 f- a [/ a" k
Selector sel;* i6 v1 X0 _) \) N* n% ]
try {0 x! S) i' @+ O* H; r' ~8 o
sel = new Selector(obj.getClass(), method, false);. x' |9 E8 d3 q- I4 O8 Z% I
} catch (Exception e) {1 n k9 T, x; z% G/ E
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "* f( j2 D* P P! H7 J
+ (obj.getClass()).getName() + ".");- q: ^, _# Y' _1 g% ]% U2 H
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());+ o9 j+ N& S* f5 K v0 C
System.err.println("The process will be terminated.");: M) q* n' c/ H# B8 p
System.exit(1);
2 R# h3 v' x& t. X# Q& b return null;
$ {, S `0 C, D1 ^ }8 O0 |+ r7 M/ U; i( b
return sel;
' r6 Q( c* M2 ] }
4 E5 N. {; n+ j3 d: _& P L! @} |