import swarm.Selector;! a0 R' T$ W- J0 d9 R0 _, l/ c- m
2 ^2 N: s1 x! f% x& y. ]( c
public class SwarmUtils {
8 }" N" d0 E7 K' p, t public static Selector getSelector(String name, String method) {; ^) _: C! p! H& Z! D9 ~0 X
Selector sel;" e. s# N* [( q6 ^# ~- [& y8 T! J% C
try {$ f* @. R7 K4 M, j( Q p& i9 g& f, ^, Q
sel = new Selector(Class.forName(name), method, false);2 h( Z2 K) B0 v! @7 y7 B
} catch (Exception e) {
9 ^& b" m" e1 S System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" Z0 k7 h1 O% a# q/ L! y( U
System.err.println(name + "." + method + " returns " + e.getMessage());. |. O) ]) t2 a9 M6 U. Z$ s2 j
System.err.println("The process will be terminated.");
) s6 x$ V" W0 Z' N- Y& l System.exit(1);. K& N7 E0 Q* x
return null;
9 l$ F$ B& p( d1 r }4 t: B( j, i) c& P6 a* v
return sel;
" \- r; b& ^4 }9 x# P }
0 A8 i0 w6 z6 j0 q# J/ H
4 Z% D" \- l: L1 P f public static Selector getSelector(Object obj, String method) {
5 c( d U7 t& \" e5 {0 W: K' N. e Selector sel;1 S9 V( [" @+ I! W! H$ X
try {
2 g; V+ Q! I g" e9 z- l, U sel = new Selector(obj.getClass(), method, false);) X) p7 i6 F5 z; `" H% A
} catch (Exception e) {4 ?: m1 X$ ]/ x3 e# @: W' ~* e3 U
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& [9 I8 v3 q- O5 o5 T2 @7 D+ j; m6 Q + (obj.getClass()).getName() + ".");
: J( V/ K4 D: J8 j System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- e4 s* n! G! D) N9 x& q System.err.println("The process will be terminated."); r- S. a& _- J& _+ e
System.exit(1);; y A1 R/ y( S& o3 Z: i! ]& Z
return null;
/ O5 U6 R Q- I }
& `* t* t" d; b( D# H# j return sel;
' L# {9 `; @- D+ r4 s0 r- i }
' g5 [- d4 P9 j% _5 w} |