import swarm.Selector;$ o# s8 G0 @( |8 t: l
, V9 Z) `" |) v1 X, t, G7 k( |5 l8 x
public class SwarmUtils {/ c9 g9 q1 T) G$ }3 s, `. {
public static Selector getSelector(String name, String method) {1 Q' i( A" r N' i# c/ R, h
Selector sel;
, l/ q+ {( o+ z( y2 C try {
8 l; a# J: G/ j5 r sel = new Selector(Class.forName(name), method, false);& v' o6 R; F$ b2 P7 O" B
} catch (Exception e) {
; G( X1 y; }& B: R) P6 n0 T3 _ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");1 I" d! d9 A. `* Z5 @: {
System.err.println(name + "." + method + " returns " + e.getMessage());
- w) k4 D- c I( B! d, z1 I1 ~ System.err.println("The process will be terminated.");8 ?' p9 x2 H) r* L
System.exit(1);
7 ~7 M% c& v' M return null;. H: w& Y" l2 [( ] U( B: N) f
}
s5 o" a3 j0 ^' t7 } return sel;
* Q' }6 l( C1 q$ L" o }
. ^7 P% |: D1 l# A- M& L' P
/ X1 [' m8 t+ S! F' f4 E" j, k$ u public static Selector getSelector(Object obj, String method) {+ ~. Z N3 Q# O. z* ~. C6 K
Selector sel;
( B8 v8 G+ Q I) s7 K try {( i, Q) _+ z8 V8 I* F Z
sel = new Selector(obj.getClass(), method, false);
9 o- n$ K9 Z4 @& H& q w6 ]; l9 R } catch (Exception e) {' V5 {1 e# m0 ]. ?" b
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" w" m9 `+ j& p + (obj.getClass()).getName() + ".");+ \! m. u: k9 T7 e- ?, \! n- A
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. x& v, V9 I% C
System.err.println("The process will be terminated.");
7 q8 d4 f, k( l System.exit(1);
5 w, m: K9 Q9 w' f6 l# a return null;
3 E- a& {) W- l. G' \ }5 V7 N4 J5 @% O$ {/ j0 Z
return sel;
/ u7 h5 X# X, x8 J. S }
( |4 Q6 ^6 F% y3 v8 r' a} |