import swarm.Selector;3 t; W4 n- e9 h W9 _) d# F
( B; k. X$ a3 T1 k1 E& x
public class SwarmUtils { r4 ~% O; F; A$ Z/ Y
public static Selector getSelector(String name, String method) {4 d+ b( h9 L: _/ b1 |
Selector sel;
' a5 |) `: T: ]9 l8 }1 E7 c try {
/ ]$ S& |6 |5 r+ G# P sel = new Selector(Class.forName(name), method, false);
" H' s5 c# G$ m. ~! U | } catch (Exception e) {1 Z. [5 a6 `4 ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& [( ?; P" `0 D/ G& P
System.err.println(name + "." + method + " returns " + e.getMessage());
/ M% i4 i& R7 Q' m! L8 V! W System.err.println("The process will be terminated.");/ Q5 y8 G y7 z W
System.exit(1);% h% L! u4 e; z6 e. o. e
return null;3 S0 j" I C! p4 m- W+ f
}# W2 G5 J+ m7 K) y
return sel;
, u! N+ ?* I. P' h( D) g4 }8 \& r }
8 @/ N! q# F& K
1 v, }+ s& q0 Q8 W/ q public static Selector getSelector(Object obj, String method) {
0 e- t3 i' q2 o9 p Selector sel;
* t# k9 Y& W7 _ try {
+ b' ?- e8 ~2 @5 V3 r* J; x sel = new Selector(obj.getClass(), method, false);% ?# k: y/ e) Z; e6 c
} catch (Exception e) {
/ j6 L. D) K8 L& M0 G& k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" ~% g! a- ]; u
+ (obj.getClass()).getName() + ".");
0 ^3 k% X3 {% v2 c- h System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
j) c1 {( J$ @ System.err.println("The process will be terminated.");
1 S- y) K' _/ k6 K u3 H/ X System.exit(1);/ }; a! B% s) m" w
return null;4 h I# V! g# ^+ K( ~+ A6 E8 F
}
5 x: o0 h5 ]8 X, |% q/ g return sel;# A' [( ~4 t5 L& q+ ^
}+ {! [. W {5 ]% V$ j" y
} |