import swarm.Selector;
* b. [4 R) m1 w+ z9 X
; E. I. N/ s& fpublic class SwarmUtils {
5 z0 v; E9 T2 N( O; c public static Selector getSelector(String name, String method) {/ ]8 _+ o* l4 v# d9 o* ]
Selector sel;
; q; i6 c: b D; M. s try {) D- y) z) l$ t- K s
sel = new Selector(Class.forName(name), method, false);" |) Y- x2 x, s4 ]+ q
} catch (Exception e) {; W" W, t) c; a) b# t: _7 Y A5 M" K
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 l" R6 x$ X [( R* z" S8 k
System.err.println(name + "." + method + " returns " + e.getMessage());
* R/ F* ]/ `5 Q! Y K2 S System.err.println("The process will be terminated.");* V3 i; a* ?3 J' h+ m& G
System.exit(1);% W1 I. P3 ]! t3 v7 h/ E2 X1 \
return null; Y& R& U2 `6 n/ N+ `! S3 ~
}# N" n2 J$ `* M9 R, O1 l( _
return sel;8 t+ X! G8 \& |5 ~( s, H
}
4 W' Q3 m5 V6 T; b0 _6 W: Z+ [6 m5 J1 k$ b m" \( v* x( r/ G# a) w: b
public static Selector getSelector(Object obj, String method) {# z( u k+ g. u$ X- z3 {
Selector sel;$ C- ]$ d D: s
try {( T. R! l/ I$ a2 W) C, e
sel = new Selector(obj.getClass(), method, false);
; g' n, m$ o: j, x* r: c } catch (Exception e) {
# Q& W* t* E$ m% j System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 ^1 \- {9 K8 k6 |" s& b: L
+ (obj.getClass()).getName() + ".");/ t4 }6 D* R+ I0 z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); S J& z1 P1 ?: B
System.err.println("The process will be terminated.");; P3 l' C N; ^ Y9 K
System.exit(1);
5 H* S ~) Z, _$ @6 n/ T( ] return null;
7 `* x3 P. C) }7 W7 G& D: H }
. j' L/ E, v5 w6 x! i: o! o5 g+ @2 M return sel;
* x3 [3 C* C2 j2 V$ V }* v: Y/ ~! W6 U# J# a2 M
} |