import swarm.Selector;
! w4 E$ d1 Z5 J5 I1 x2 f1 K
8 J. s4 i0 G) O2 |. [- upublic class SwarmUtils {
: j5 n+ [% X+ L8 D! E& B public static Selector getSelector(String name, String method) {! W: e: Z% r" I3 M# ]! K
Selector sel;
7 L8 m K, k+ i" \8 o. r+ @ try {7 s" H( |1 v8 n9 P$ E' j7 l
sel = new Selector(Class.forName(name), method, false);: ~8 j& n( a$ X/ R& J# N5 n
} catch (Exception e) {1 T* [' F) }' y& z0 g# N/ C A1 \
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");+ z/ B8 y9 J* f0 E- ?& s* d0 ?0 p
System.err.println(name + "." + method + " returns " + e.getMessage());5 A7 _9 A/ E+ T7 _: j
System.err.println("The process will be terminated.");! o+ j z8 I Q; @% b8 K! B* N
System.exit(1);
6 W" ]. u0 x$ N8 t# C return null;% A) m& z7 ~/ Y7 N
}
# `$ C2 D; I4 [% L- O0 m return sel;9 ?& S! U' c4 @* J2 |+ Q
}/ L3 Z% G5 ?3 [+ [9 Y* w1 _+ m9 t
/ W. ~9 W# |5 Z, ]; Y0 ^: M6 V
public static Selector getSelector(Object obj, String method) {- U" {2 E5 h" h( G
Selector sel;) F: ^$ c. V" _$ m, |3 m7 P+ ?. N9 r
try {
\. P( b/ |# ]/ }& I sel = new Selector(obj.getClass(), method, false);
5 _# b& g5 b M } catch (Exception e) {& v; \6 v. V1 k. R9 M
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" L( Z3 |, P F8 O1 b8 r; Q + (obj.getClass()).getName() + ".");
4 i2 N' t2 g5 a% G5 U; @ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. |+ \) Y% l8 o. F- K6 @, v
System.err.println("The process will be terminated.");
6 l3 z( M2 W+ P/ |8 j System.exit(1);
/ E$ N. [( Y9 Q return null;
3 F V( W/ b/ n; @; F1 a( ~ }; j. E: M' P/ }. E" ~
return sel;6 |% p8 B0 p7 \
}
, a* T- q: Y2 v: I} |