import swarm.Selector;# Z( l9 F$ I- M$ c5 q6 i. [2 s
) E' g6 Q7 [8 W: _% }+ Qpublic class SwarmUtils {
) a: q; s4 v& v; K4 B& @ public static Selector getSelector(String name, String method) {$ ^/ I N9 V0 i8 A( i* X3 a
Selector sel;
- l0 l$ P, D4 y' n* e4 }3 S try {
& G6 v' V' M- j sel = new Selector(Class.forName(name), method, false); Y6 [& M, i6 M% x1 m: h
} catch (Exception e) {: u7 X9 z- A }+ N1 @2 \" M
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ @/ n- L) W( P5 A: y System.err.println(name + "." + method + " returns " + e.getMessage());( N& @1 p$ [+ e) K( B+ c+ r! ?
System.err.println("The process will be terminated.");
7 @$ ~* v, K: G) U$ H- t& H System.exit(1);, d( V& e) T+ y3 S
return null;- x) d2 ]9 P/ j5 _
}
1 T) r5 j. R- W: R8 h return sel;
. J# [# Y8 Y5 l! L( J# @4 R0 D$ G }
: x( N, q) K8 i# h5 z7 z/ Q* o& w0 z$ |. @$ j$ Z% @1 o
public static Selector getSelector(Object obj, String method) {: D. \6 X2 f0 N7 f: p0 _& M
Selector sel;% Q' x$ i0 Y; q9 {
try {
/ ~' s& a* R) b' D M; c0 n sel = new Selector(obj.getClass(), method, false);# b# f; u! y8 m3 h7 |, t* ]; B1 J4 \
} catch (Exception e) {
( R2 s& D) C$ G" r$ h7 F! R System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
, Z& a k/ H; r; C, D + (obj.getClass()).getName() + ".");" S, E: @0 L+ b& h1 s6 x
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 A1 j9 }1 k* F t# D' c4 r
System.err.println("The process will be terminated.");% P& W! y" U" q1 J0 O
System.exit(1);
# }3 v; H5 n9 k, O( x! N3 N1 s1 v return null;- a! l+ D* b" c/ j3 e3 g
}
! ~1 Y. G+ z6 B1 V. A return sel;6 H2 r1 X, e I# G; S* q! e
}
7 t* Y! N' g8 J: F# |5 k: w} |