import swarm.Selector;+ N% V3 {4 O- g! O$ @: e. I
% a1 x7 F1 m X1 gpublic class SwarmUtils {7 z; W% j& K) [. e( ]
public static Selector getSelector(String name, String method) {7 f6 O/ E5 F# }/ c5 V
Selector sel;
A1 o/ z3 p1 O0 v0 L ] e7 t try {5 E, z: ?% C% h
sel = new Selector(Class.forName(name), method, false);
# V) `4 V |: [5 [, t/ U } catch (Exception e) {
+ `3 g; Z# t3 h, }" X System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ e0 c6 q7 F; M0 v System.err.println(name + "." + method + " returns " + e.getMessage());
+ z% a8 A, m( _ System.err.println("The process will be terminated.");5 L) e* Z* H: Z0 c' C
System.exit(1);
5 z E* p9 a3 u$ ?' G return null;0 f/ B- ?' L9 b3 u+ s5 g8 ~4 R8 x
}
8 E8 C1 Q6 y( ^& ^4 W7 i+ \! N return sel;& ?" A' Y$ S' O
}
- R% s6 N1 G- C; P7 H+ Y% _# t" h
# a7 O# k( X; T% C public static Selector getSelector(Object obj, String method) {! v v4 |* P% ?1 Q
Selector sel;) [* r8 P* `' y- U# U
try {8 C) z" v6 j: N$ P8 l8 c& {5 x# H2 w g
sel = new Selector(obj.getClass(), method, false);
; k0 X; _# r# @5 Z7 c3 s2 K } catch (Exception e) {
$ t+ v( f: c" t8 P/ I6 b System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ n3 T2 ^5 |8 t2 ]# B( w
+ (obj.getClass()).getName() + ".");$ b$ f2 C4 Z( f+ W, O+ v
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
; K7 D9 G% Q4 U! x' C, J System.err.println("The process will be terminated.");) G. e+ h: b0 F4 @/ W3 k) B
System.exit(1);
5 F, q- n/ J; ?- G% t" M T$ l return null;
. d/ B7 c4 b# K" ~ R }1 @! C+ ?. z1 a6 f$ \( _; [9 z
return sel;( s) q" ]1 y# B' H; D
}6 \/ v( `( V3 B6 s# J G5 t
} |