import swarm.Selector;1 m( ?8 m9 O* C) v5 m `: ~3 t
8 v& E1 a0 y) L( R6 A9 _4 e4 c# a8 @2 f' kpublic class SwarmUtils {
. q3 x( r/ m% X( B% ?3 o public static Selector getSelector(String name, String method) {! K4 t- ?& B0 j( Y; k3 c2 t
Selector sel;
! c/ o% d Y# |, q1 K! W# v$ b try {
/ z$ V6 i# s Z% k$ B9 Y sel = new Selector(Class.forName(name), method, false);( i. J+ l3 i% D, p
} catch (Exception e) {
# J8 c3 I8 Y5 p( Q* d" a System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. [" r. V) S0 V0 _ System.err.println(name + "." + method + " returns " + e.getMessage());
8 q! \% I9 V% e n& R0 u System.err.println("The process will be terminated.");
' \0 C3 C) n+ O3 ?6 s3 M* \' ] System.exit(1);
. ~3 A6 C: d: U( v/ V return null;2 |# m- l9 T! r5 D: k
}
: V/ x4 c8 _: j/ m return sel;
% v, ~5 i" ?* }3 ]# X( m }
4 m; O- {/ \4 _# ~2 ]: X5 L9 Y2 D) S+ n- w
public static Selector getSelector(Object obj, String method) {% M7 P Z' G% @1 l* x( N% [
Selector sel;/ g' z/ m! T. ]5 R5 @& J! u
try {
0 I. k6 K; d6 H# ?3 ?( o- h$ U% I6 i sel = new Selector(obj.getClass(), method, false);
4 G- j& \7 c- L# p } catch (Exception e) {
6 r8 w8 T) [$ D9 w j8 ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "- G4 }7 g, a4 M- m. I. w
+ (obj.getClass()).getName() + ".");3 Q) d* B. O( t, V
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ u; q) [! P) N* } System.err.println("The process will be terminated.");
# H7 t0 q/ z1 k S, c, I- b# N$ N" d System.exit(1);+ W& h. {, a+ t" m9 z+ y' E [) c
return null;
4 @9 D& w2 f' z) M/ { }
0 a9 b+ l7 l6 G0 n return sel;
8 v1 d! C$ c6 ~1 k% _ }/ o& ~( S6 O( s* J
} |