import swarm.Selector;
/ g: e8 y: b! |8 T! F* r$ {3 s$ p/ I6 c
public class SwarmUtils {5 n" n: A) b$ L |
public static Selector getSelector(String name, String method) {
6 O& J% s$ B) l: k Selector sel;
. a! S+ S+ G& X) e) ~. x. H! \. [4 N try {
3 t) m2 p" X& t$ N) O4 G% \% k sel = new Selector(Class.forName(name), method, false);, r7 C, F2 f0 W+ s( s$ T8 A# [
} catch (Exception e) {
( I8 f% b' U) n4 ~' Y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( A6 m0 y* o5 G. S; L: u6 n/ L System.err.println(name + "." + method + " returns " + e.getMessage()); U" m- W1 l5 Z2 C0 m
System.err.println("The process will be terminated.");* \' [; t [' N3 q
System.exit(1);# R$ T: p+ m. F
return null;1 J+ Q/ x( c: Z6 q) N+ z1 I& I
}7 c* i% ]7 g8 d( H% C" C
return sel;) M$ L9 x. G1 J$ c
}
5 n5 b( g( n5 C% }. p. H4 A& M0 p1 k8 M/ A$ {9 Z6 t! e3 u \+ m
public static Selector getSelector(Object obj, String method) {
( L! o8 i1 G: v Selector sel;* {, A7 N( _% S% ` [
try {& R2 Q2 V0 |+ \- L" _3 f
sel = new Selector(obj.getClass(), method, false);
9 \1 o" j H/ c3 A } catch (Exception e) {4 Q" S/ a8 f, t3 f1 ` ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" V! S3 R0 X% p# H
+ (obj.getClass()).getName() + ".");1 {% s9 ^' C/ P0 A B' v: {
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());4 d, m1 Y. I/ t- Z
System.err.println("The process will be terminated.");3 m! M2 k7 V. L3 g b
System.exit(1);
( n9 a; W: ?* E3 s5 ^ return null;
1 _1 m3 l# t9 ] q }( `' K2 I5 r. h$ J% m
return sel;
8 y! r4 @$ _, \ }- j0 g5 F$ I! c9 W# H7 }" K! @
} |