import swarm.Selector;
+ { y; m; u# w% J3 P" c( n, j. T: R! u/ y! \+ N
public class SwarmUtils {0 l5 m- F1 I! m7 Y F" g
public static Selector getSelector(String name, String method) {. |% u; r0 N7 ^6 r( J
Selector sel;( ?9 ^! Z |0 G! s
try {
! K. I5 R0 J0 x% Q sel = new Selector(Class.forName(name), method, false);
5 z) F, O3 X: F } catch (Exception e) { V8 t% m( W' I2 L* ?/ n& j* v
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ R7 U+ d4 v1 }* @* t
System.err.println(name + "." + method + " returns " + e.getMessage());
, w; b8 F( t( Z8 ] System.err.println("The process will be terminated.");
! z9 V8 R8 R6 c# J9 Y9 a* F$ j System.exit(1);* H) ]# @" T) V5 g2 ~; r
return null;& _( J: t9 F3 e% C
}% R4 [ P) I9 ~
return sel;
; n: m0 p3 N( Q! ] }% }( F# f8 x+ ]$ a% J# |
8 }7 U8 A+ K- I4 l; h8 j& } public static Selector getSelector(Object obj, String method) {0 {) a6 a0 ^! u& ]' ^: [
Selector sel;
$ a% }) L6 c* `, `% I- m try {3 l' p, Y- }) m3 Y, Y! r
sel = new Selector(obj.getClass(), method, false);
: w( ?- v' o* z2 F4 n: v } catch (Exception e) {
A2 _: X0 t. ]+ j6 b System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ T" B* o. ~8 Q6 r7 t9 \
+ (obj.getClass()).getName() + ".");! _/ S9 c4 R% }' i8 J: L. s0 U0 `, {
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
" z# w" k% m4 ?7 \! t( k6 R System.err.println("The process will be terminated.");
: y G/ _: j4 M6 X5 f5 l) C System.exit(1);
! G2 c. r' p b: R) Y return null;
( v& C u9 O/ Q0 |! P8 { }6 S1 T7 P# W3 z5 [( n$ ^' G
return sel;: o( A Q# D4 m; U# y
}0 N- L, Y6 F# N& C0 T+ t) s8 A q$ d
} |