import swarm.Selector;, d, _# ^3 v) n$ ~" c/ H
# E1 Z: r" |9 T* s+ U- b6 a
public class SwarmUtils {) j; }3 w+ F v1 K2 @0 ?2 j
public static Selector getSelector(String name, String method) {9 v& J& Q7 [/ v, M8 Z
Selector sel;
: _4 o& y3 Y3 g5 i0 u" X' X try {
: H t% l$ a/ y2 n sel = new Selector(Class.forName(name), method, false);
) t( e- l3 b5 {0 N8 K3 C } catch (Exception e) {2 m3 C; Z4 ?) b9 |4 {
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");! `9 a# j4 r. D. e
System.err.println(name + "." + method + " returns " + e.getMessage()); D1 D: T! Y- G1 l+ f- q; \4 B
System.err.println("The process will be terminated.");: f* p7 ]$ e7 @& {2 k' A' h
System.exit(1);3 E- Q+ P3 Y5 P9 v: G7 ~
return null;
" P- k8 B/ c3 x; D+ q# w/ j+ m }
* o- A7 J n# J# C/ o return sel;
& @: }. Y0 H+ K- s6 { }7 w' g: \8 b$ a
7 J- l$ l1 N5 i' S0 q# v D public static Selector getSelector(Object obj, String method) {4 d j$ G+ i: P7 X( J- V# [6 X
Selector sel;. O( v! o1 g' _' U1 O
try {; m v: O% l" L/ v3 _7 O% D; k- w
sel = new Selector(obj.getClass(), method, false);
1 G6 a. l, P" [7 k } catch (Exception e) {
+ S2 ~* _9 J+ ~7 @5 `9 d6 K: i, X System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- c( x$ _" X5 I0 S1 A J6 B$ v, [ + (obj.getClass()).getName() + ".");9 A% e+ _: e5 t2 z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 C# M1 ?7 Q r3 w System.err.println("The process will be terminated.");
9 G3 ^: X2 i- ?' o* K9 z5 S System.exit(1);3 V" {7 q9 x* l' q3 Y
return null; X8 M4 N& j! a* v* ?
}! m# q! ?, [3 g L; d. U* M
return sel;
6 L2 q9 d1 L4 T& w0 `7 U" e" M6 N }
, W: D b. L1 Z/ M) r1 _} |