import swarm.Selector;9 D5 \ Q' i$ Z- m
6 e( y8 T: V/ p3 g* ppublic class SwarmUtils {0 l0 j s0 J5 l. @
public static Selector getSelector(String name, String method) {
, |& I, M) p5 N9 }' S- ^# h Selector sel;! i$ m3 R k6 T
try {+ @1 ?* |; d5 b! i3 Z0 {6 F
sel = new Selector(Class.forName(name), method, false);
" ~1 z, @. h6 M/ R( Y1 }3 e } catch (Exception e) {
* x4 S9 d, z$ j& i& D9 `2 ]& x System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& @6 W8 k! i9 F d8 [6 N
System.err.println(name + "." + method + " returns " + e.getMessage());8 v: E6 W& U( n$ H; v/ g o+ e( d, l, R
System.err.println("The process will be terminated.");" |1 s5 \& U# z: c; f! |8 M
System.exit(1);
3 z7 y# p" V' R4 t return null;7 X4 c3 D5 F7 m G) O- j. X0 [
}% B$ z# p9 z7 g$ ~9 t
return sel;& p$ G5 a" c6 x. P" `
}9 n% x8 o7 ^7 t+ |4 z6 M& W
' M6 M3 K- d4 a, R% J% _
public static Selector getSelector(Object obj, String method) {
X7 [& e9 j; k* q* H Selector sel;
J) V" E3 X5 H6 f try {! @- ?' `9 Q) o; g, z* c3 l7 [' {
sel = new Selector(obj.getClass(), method, false);0 w! a6 j# ]/ D9 @
} catch (Exception e) {4 ^- R1 p0 J. r- O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' H( Y v5 w6 q& R* \
+ (obj.getClass()).getName() + ".");
; B" A+ d+ t( T0 ]2 j System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());3 P) R. o( a$ }, ^. \* V ~3 q
System.err.println("The process will be terminated.");
: T' Z. @+ @0 F System.exit(1);
( _6 G- I4 o0 m4 C return null;
1 ?) W" A6 a! o' u: ^ }
4 ? x* H" U/ }, @$ _ return sel;( O' f: _- d2 h) H7 F8 T
}
! {; i6 H, T& E9 R, S2 P} |