import swarm.Selector;( R6 t0 ^6 X1 k1 z8 M6 ~
6 u5 E) D/ K4 A. Mpublic class SwarmUtils {
' a/ R6 ^6 ]6 H: l6 Z6 Y public static Selector getSelector(String name, String method) {5 q* s- R+ `& x3 ~
Selector sel;
) _* y* g. F: Z, w5 A4 ^ try {6 U, j: b0 A- x" a) @) R o3 e
sel = new Selector(Class.forName(name), method, false);* C' R; a; t' b5 C: _9 B
} catch (Exception e) {+ y- f+ J9 K" u ]; r% b: N
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* i) y( [# V; }( U# [* a3 Q System.err.println(name + "." + method + " returns " + e.getMessage());. E0 o- n5 O7 g9 i6 K5 [
System.err.println("The process will be terminated.");* y; b; S% l" J+ P, W6 `; W
System.exit(1);# K5 ?4 i5 g2 |
return null;$ B/ _- K/ A; ~
}
2 g& s; C. k, M8 p! Z1 `; g return sel;1 t0 t; S1 l, ^, k: T
}" q9 R( h+ P# R- |+ c/ N
1 _9 W) Q- i/ r
public static Selector getSelector(Object obj, String method) {3 W1 \' ~1 c3 i+ T) [
Selector sel;
, y/ A% S# @. q) @9 Q try {
! M& A4 p9 U1 ~" @& ^9 T sel = new Selector(obj.getClass(), method, false);
1 n6 E6 D; k- i } catch (Exception e) {
6 w' P; \# i- z7 I5 S! O- c System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# M( b3 h7 j3 `: l; g; L- | + (obj.getClass()).getName() + ".");: j( G+ F; ?) A: x! b/ ?. A
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ E, f u7 B! i, M" l; M( Q System.err.println("The process will be terminated.");
: V2 M) @' @; ^6 X/ } System.exit(1);3 W" P7 E8 t) A
return null;
! ]3 ]7 m7 u1 w }
$ O, P* \5 m1 d- V return sel;
8 h# ^: s {1 n# ?& ^ }+ @- C, R# G! X, P( ]
} |