import swarm.Selector;7 n& Y# d. p) v& I
5 r4 I2 T! C; i- G
public class SwarmUtils {
; V+ \; C7 a+ R1 g( E public static Selector getSelector(String name, String method) {
$ r! M: x! c' I$ X Selector sel;7 h, w! m8 P, v" L% ^3 u
try {2 O) t* U7 e6 I# w+ D4 Z1 f
sel = new Selector(Class.forName(name), method, false);8 B4 t9 @7 P4 G
} catch (Exception e) {
: P: u. |& P0 J# c System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");' `% @9 j3 {: i: d9 G9 F+ Y7 B& g9 R' l
System.err.println(name + "." + method + " returns " + e.getMessage());- }: @4 f# I0 ~) p+ K
System.err.println("The process will be terminated.");& B: F2 S4 a+ r+ T! s
System.exit(1);
! [+ q. l' g9 W return null;" ^& A! H3 [- R5 }5 W+ B: C
}
/ g# ^- e- b& I, q) g: g3 c return sel;; v9 j5 A3 y( ^6 t
}
+ z. {5 n; j8 l5 G+ \
; J0 c; m8 B" |- k public static Selector getSelector(Object obj, String method) {0 T% G+ F4 u% m; i1 z% ~
Selector sel; O# S A# g3 |; Y
try {! j* a: X9 P, F' u
sel = new Selector(obj.getClass(), method, false);# B- v2 {* [3 R% V d( |
} catch (Exception e) {) H- i" H1 R |% W/ o$ r
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "3 [& V" r7 U& `8 k
+ (obj.getClass()).getName() + ".");
7 o1 l8 P0 L( x# {. m7 X System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 G, b+ K/ `% c3 V% a/ x
System.err.println("The process will be terminated.");' l. \* x+ d- |0 X2 h" o; l* m
System.exit(1);
5 E9 d8 J& F) f return null;! L! }3 o& h: P {* G
}5 v! X* `' E; [4 H: s
return sel;
7 J+ {2 r+ _3 @. T }7 M: S$ V! h0 r3 Q: |1 | H# W
} |