import swarm.Selector;3 h: {8 c4 y# d( E
4 E$ ~7 ^$ `; z* @1 Q0 ~public class SwarmUtils {3 {& _% _! C4 U$ B! B, G- @
public static Selector getSelector(String name, String method) {
* Y' n" o% m0 a& w5 p3 z6 Q Selector sel;
5 X5 h5 C$ |* m try {- [, c" q x0 J7 a5 ~& M7 y3 ]
sel = new Selector(Class.forName(name), method, false);- O9 h1 {4 U) r7 s, s* J- c% M5 V
} catch (Exception e) {
+ m- g0 c$ ^& j1 b T) O System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
3 M1 v0 k2 Y+ M: l7 Z; z8 t System.err.println(name + "." + method + " returns " + e.getMessage());6 ?! ^+ H! w6 W# k0 v' n
System.err.println("The process will be terminated.");
4 o9 b0 _0 I; z4 L( e* _ System.exit(1);
6 ]/ D" |9 v- z# D7 [5 l0 w return null;
/ a; F$ q) e+ W% ?* r' u/ T9 d- R }% R) s% E8 c6 c# j |" A$ m5 V ^4 a
return sel;
: a$ y# y( X" N- P. ] } v8 W7 G. F- J) J; K
5 e9 @9 D: O/ H* o' ~
public static Selector getSelector(Object obj, String method) {$ I( h9 W: L" f! f, X2 e
Selector sel;
1 Q4 p* @9 r$ a" N4 X% E) n$ t try {
" ~; G9 ~) X: Y$ n; a sel = new Selector(obj.getClass(), method, false);7 p8 D7 c8 h2 S+ v
} catch (Exception e) {9 J" I( m5 N- S0 ]) u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 U. X& y* a. o
+ (obj.getClass()).getName() + ".");+ I/ ^& i2 N8 F
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, G! Y1 U) n. W
System.err.println("The process will be terminated.");0 s' W0 S! Z& G7 m# c$ _
System.exit(1);
, l5 e7 P: A& T% q return null;$ L3 D. N' g* ~( ?5 ~6 Q
}
( Z9 u2 {" x% E- q/ |) N6 h9 k* U return sel;
/ r6 k/ l& H, z" C0 n" e }
* T) D$ m4 v% ]} |