import swarm.Selector;
1 w6 ~9 N8 }6 d! f f7 b- d0 ]+ Q2 \. K7 W
public class SwarmUtils {9 V' Q s3 I8 Z0 u* }& q, `$ W
public static Selector getSelector(String name, String method) {
m3 d E2 e. G Selector sel;8 r) v+ J9 r! w0 u2 w4 m& b
try {/ ~( \" H) C: f6 ]2 c
sel = new Selector(Class.forName(name), method, false);
9 P/ `2 z! Q8 l% p8 n) _3 S } catch (Exception e) {: D5 G9 n$ j& l. y" n' n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 u% c4 X/ c5 f) D
System.err.println(name + "." + method + " returns " + e.getMessage());7 a) u- F5 d" O E1 Q- I* ]
System.err.println("The process will be terminated.");
# h9 D6 R- C6 N- @4 Z: S1 T2 Q# g System.exit(1);
9 X, W1 m8 V7 h6 E6 T" i$ E( L return null;
2 u8 y* N b J" r7 ]! | }
5 T/ M; [1 {6 N$ k* z return sel;
( L8 }7 j8 l9 }+ N: H( m }
9 F( v1 P; S- G, x
+ e7 _- }+ X' @) j# l public static Selector getSelector(Object obj, String method) {
/ @2 `4 v# ~( F$ Y2 s, o Selector sel;
) w% h2 ? P0 L0 Q; m G$ e4 ^9 O try {: D5 Q& a0 C1 L4 D
sel = new Selector(obj.getClass(), method, false);$ k8 P; p- k y( O% e& o
} catch (Exception e) {( k; E1 ^ }/ b* R( U _2 Z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; d) M& y* h9 k- S: u
+ (obj.getClass()).getName() + ".");5 S8 D9 v4 w% g: ^) j3 x: K; B6 G
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());4 N% q, t9 E4 V- a1 h+ i8 @: z7 U
System.err.println("The process will be terminated.");
) y3 ~$ @8 @ z- d3 _, W System.exit(1);
. f& M* F/ r2 i m% n0 c$ }+ q return null;
& V [, p! ?& `5 J! R3 {, Q9 A' D: H* C }* j, A N% J% W9 ]5 {5 m0 c
return sel;; \; q B9 c( {, a
}
$ \% x7 A# Z* W: V9 ~) W/ z} |