import swarm.Selector;# l7 e8 q" ~8 `: l& s' d
4 A8 v; m3 b' f6 @% I* g
public class SwarmUtils {) |- L. [; M$ e& X, i
public static Selector getSelector(String name, String method) {
G. g9 [$ n! b S6 B Selector sel;
" S8 @5 x! k" K# X+ c# x( s/ C try {
& C3 I: w) Y' A8 j ~9 n sel = new Selector(Class.forName(name), method, false);. b% a1 W! H0 M1 U
} catch (Exception e) {
" y% ^# I. V8 S: b0 s; u System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");$ {7 ^7 N! R6 E1 q& _) G9 `/ j
System.err.println(name + "." + method + " returns " + e.getMessage());
5 e! C6 v7 e7 e6 w System.err.println("The process will be terminated.");
. h6 s( P e" l* M4 t! ^- ` System.exit(1);/ N3 ]- n* s8 F6 [0 K
return null;
! Z3 D8 [0 R4 M" |* a }
5 r1 r0 j7 {4 k. Y0 o) j0 B6 K return sel;# g" ]1 R, |" c+ s: ]0 B" V
}, X7 I7 W7 n, e( n0 x
3 R8 O3 }- k: C* t4 N3 ]6 s
public static Selector getSelector(Object obj, String method) {' z C- \5 m* P: X9 y- M3 @
Selector sel;" I2 b6 i4 v7 N3 z- k! s
try {7 l/ q5 E' `* x
sel = new Selector(obj.getClass(), method, false);6 Y( E2 D- I( V) z! @: X4 M
} catch (Exception e) {! i6 n. I% u/ A1 H
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 v1 t" V3 q+ b1 \ + (obj.getClass()).getName() + ".");1 Q' ?3 a k9 d8 k9 V
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( R# H& g* c( o& ^ z
System.err.println("The process will be terminated.");& C) e. |: k0 o& R7 V* {7 Z
System.exit(1);
; a9 m& v2 V; O6 B1 S return null;
( N9 w4 z5 j$ g1 Z/ Z9 C }* @$ R+ Y' l' a* I; r
return sel;
( Y0 n1 z/ P& r2 X9 b }1 I! d8 G- z! W% } Q: e/ W
} |