import swarm.Selector; v4 D7 C, k' I! H
: E. e8 G+ B. e/ v+ n9 D
public class SwarmUtils {
8 ?0 h1 H" `/ O) W- o public static Selector getSelector(String name, String method) {3 z9 D% `- F$ y6 ~) g! f5 ~2 ^7 ]- Z3 C
Selector sel;
. a7 }" `5 f! ^1 A% @ P try {
+ a5 [! A; p: X sel = new Selector(Class.forName(name), method, false);; [# j# O, I8 q: h& v. X! U
} catch (Exception e) {: l) w8 a7 l* w7 ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* H0 Z: Z" U3 T% r" m$ L$ } System.err.println(name + "." + method + " returns " + e.getMessage());) w3 `# }' U+ |* k
System.err.println("The process will be terminated.");9 g2 r: a5 q. t
System.exit(1);
3 V& i& i7 f0 F! [) _) I! @ return null;
3 X' l& f# N" I# y/ u }
2 Y' Q5 Z% c; A9 ~( k6 J8 r3 T# F return sel;
0 I' i- P$ j" |0 @8 i; A6 } }
, h( Y9 a4 W7 j* Q' V7 B! X2 s
9 S6 z# ?. ?" U( W& \6 [1 o4 K public static Selector getSelector(Object obj, String method) { I' v! C% o+ ^7 }- s9 F J
Selector sel;, F$ C9 a' R* D8 _$ [ E
try {
- |2 ^& w8 C0 Z+ d) l2 j, D sel = new Selector(obj.getClass(), method, false);: z8 \5 I; T6 w+ `8 b6 o d9 d- ?
} catch (Exception e) {. g; E5 _$ X& X1 \: D
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "( g7 i9 A7 ~1 \
+ (obj.getClass()).getName() + ".");
9 |) A b5 [' z$ S- r0 `# { System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
! T. Z' L0 P$ Q( K( U4 g( f1 | System.err.println("The process will be terminated.");
5 p5 _: v) e o B1 _ System.exit(1);
2 Y) t7 o8 ]; A# M& k return null;0 ^1 ^2 J5 ~1 z9 R
}
8 \- e7 Z0 h8 h5 Q6 a! U return sel;
8 i- ?0 X: E/ M2 u4 e }% p4 E3 {# N' z: Z' v( h" e
} |