import swarm.Selector;
$ h+ }# x! j2 A4 k1 `, O/ X! Z! k# y4 K+ E! G+ \
public class SwarmUtils {& e$ U `" P( h& X5 q8 V0 H
public static Selector getSelector(String name, String method) {
$ R P. m) ^& Y! F7 y+ }( V Selector sel;
4 g. ~5 t: V0 b/ J& B. `0 j, e- O2 g try {
) n5 _# z) h l6 C- V5 f; V& o) ^. E sel = new Selector(Class.forName(name), method, false);! \% ^) J! A6 ~3 U
} catch (Exception e) {
0 _2 n# B% {3 C% t$ m: n/ p- n System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 @5 l. E& E9 f0 w$ t- }. N
System.err.println(name + "." + method + " returns " + e.getMessage());
" M( G! Z, l7 o3 F( ^' I System.err.println("The process will be terminated."); n# f3 w' o9 ~% c4 A* Z
System.exit(1);6 }! d5 ^2 d6 n7 I+ I7 k6 ]" ]
return null;4 _' k! S4 C/ F. C
}
7 h1 H3 W( n6 D+ S$ h) h return sel;! u4 n8 i- o* W! V
}: P% ?* t$ \: v4 s7 l5 ?* e8 {
( Q2 K, r1 O' S0 D
public static Selector getSelector(Object obj, String method) {4 D+ b$ M' N: D: ^/ v4 X' c" j* z' y
Selector sel;
7 r5 _$ v8 |0 b U2 ]3 D9 Z8 k7 N try {9 ?% s- _5 L- |: }8 p, Z
sel = new Selector(obj.getClass(), method, false);
2 C% b' y$ p1 T1 q } catch (Exception e) {! ~8 C: f8 z" x
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "1 h, r, F' Z; X9 E7 S3 o$ S
+ (obj.getClass()).getName() + ".");- k, o @, c2 M1 w/ w. D. O
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! R4 \+ q5 s3 V) Y& q# G {1 h! c
System.err.println("The process will be terminated.");* H9 u% S8 Y% ^: M! M
System.exit(1);
* f) Y1 _* L/ M3 L return null;: a5 P- W8 m! y1 G1 ?7 r9 g" F) I& \
} [) _- B' w; u5 p; k* y' G! v: \
return sel;2 I1 Y h) K7 ]9 h2 d
} I; X$ v/ v$ l- j- p' w
} |