import swarm.Selector;# l/ k8 M! w$ e! }6 v9 K
( ?' w9 k7 @; v
public class SwarmUtils {
* f% q' y3 W7 l) m2 j% y9 ^ public static Selector getSelector(String name, String method) {
3 l2 `, q6 Q3 [2 `6 G( N Selector sel;# _3 ?, [5 z1 ?& i% g Z* J
try {0 G6 ]2 N8 R# h" I" d1 o
sel = new Selector(Class.forName(name), method, false);
# R& Q4 i E# ]& ?, q$ ^. j } catch (Exception e) {
I( f/ |0 ]" a1 F# m# B1 z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 D+ K; O+ W& q4 B7 U3 Q
System.err.println(name + "." + method + " returns " + e.getMessage());
[4 b9 ^4 O- h$ A System.err.println("The process will be terminated.");
9 s# @2 R5 m; b5 b% } System.exit(1);$ h( B( _4 c: E# ~0 z$ I
return null;2 s2 X3 C) s" d$ Y9 O
}) B2 W* p1 }: J* [! ~! d* x6 R
return sel;
0 [7 j. a6 @/ M A }
5 G9 Y ?7 T4 l# z/ x% [5 \: B/ ~2 k, k% ~$ ^ E- k# x
public static Selector getSelector(Object obj, String method) {. B0 o3 v2 J, X2 o( }
Selector sel;6 t1 y$ n. o# S: p+ o9 @2 [- @
try {
7 j! }6 h! K! z2 ]( X% q sel = new Selector(obj.getClass(), method, false);
2 _# i0 Y# G8 H" a# A( v/ K } catch (Exception e) {$ {* z# n- j2 s6 E5 ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# f& \% U1 m& [+ C + (obj.getClass()).getName() + ".");
( Z3 H k# a+ Z; c7 a/ f. E" ] System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 e( z: m. [6 q8 E7 ^. O+ M System.err.println("The process will be terminated."); S& ~& I+ B: R2 ~ N O8 x/ M
System.exit(1);) F* `0 ~" Q& c. ^) f% r8 C& @
return null;# A7 X9 {/ K! C- r" {2 ~ b, K: V
}
/ w" \/ M6 C5 v$ D* l6 F0 A return sel;% C* C8 L6 i7 {& Y
}
0 I! U! b! [* s& P* X4 X+ k} |