import swarm.Selector;$ c# y5 W. Y7 X. G* q! m
( O1 U3 B0 @0 g
public class SwarmUtils {
" Y& ?* h3 m" C public static Selector getSelector(String name, String method) {. _$ e7 ]% f! K- ^; c4 F
Selector sel;& N) J5 [% V; P7 X' M) |
try {8 e* F8 o+ o+ }# R0 R' z4 ^
sel = new Selector(Class.forName(name), method, false);
3 X2 a0 c/ p2 u' Z } catch (Exception e) {
' M3 U* c4 b: y; Q s, @; w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");# }+ f# I0 i8 [4 Q' M
System.err.println(name + "." + method + " returns " + e.getMessage());
) A2 R, G/ b: h& L System.err.println("The process will be terminated.");
& d5 E/ f7 T0 S$ h z' n/ I System.exit(1);
0 K \2 @$ T# v$ ?* K2 t9 p# Z4 v return null;+ k& x& ^( @( O( V1 C8 O4 E/ d
}
5 c3 i, y9 q! f" L return sel;
0 J: S B4 `% N& I7 z }
# g5 v8 c6 y7 y6 `& `- c( ?; C# |7 f4 T" N p/ m( _( [/ ]
public static Selector getSelector(Object obj, String method) { B% G6 W: Q9 I/ w1 V1 Q6 Z
Selector sel;
. ~6 p. [$ `7 `, Q9 Z- j% Z8 k try {1 v6 s8 e7 ?* j, i
sel = new Selector(obj.getClass(), method, false);& P/ m8 s& U; [' |
} catch (Exception e) {9 w i( J$ c! w' ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ W/ x B9 a& i9 ]: }( F2 v0 A + (obj.getClass()).getName() + ".");7 p, p/ q6 {8 g z5 ^+ c
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* o7 y4 U5 N' w6 _. s
System.err.println("The process will be terminated.");# I) v, ?- m* H: A
System.exit(1);6 A& {$ m# l6 w+ O( J' c0 V9 w
return null;5 ?) h8 i/ S$ t7 I+ n
}
) y1 V6 Z" d6 P/ e3 k return sel;" O4 x f h- G5 q
}2 X$ A* v0 s3 |% I1 i7 g0 v h
} |