import swarm.Selector;# e, a% Q* K v/ v
9 Y& W& U- ` @8 ]+ `) a* p
public class SwarmUtils {; p9 v+ p! E/ n. B2 V3 A3 R4 O+ G
public static Selector getSelector(String name, String method) {6 R3 l7 f( n+ f. [+ k
Selector sel;( @3 A+ m. |: L+ @0 @5 f) J4 n
try {
3 a3 B, o6 w* w; H0 B! g sel = new Selector(Class.forName(name), method, false);& l0 e9 }0 p' p0 P- ?0 H- e; `2 W
} catch (Exception e) {/ z/ a# E' U+ c3 b3 T& l8 g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- C! [8 Q- ^; S9 K% ], v
System.err.println(name + "." + method + " returns " + e.getMessage());9 u" _0 @& H( n" X
System.err.println("The process will be terminated.");
$ o9 x4 [: q& Y; e b7 Y5 t System.exit(1);
6 Y8 d% v3 p% d, z8 k9 e: _% l, f" Q return null;
3 {6 |! [( [" Q0 d5 { }
; U& K& R3 z6 Q0 R$ b return sel;2 H2 ]& `' Q5 [+ Y! c4 u5 @
}" a1 l5 r7 _' H0 a: f2 g, Q
+ T$ Q+ b4 G0 ~8 ]9 B
public static Selector getSelector(Object obj, String method) {
0 f2 b3 ?9 a. N7 _' H0 j Selector sel;
3 G' O" x# l. o, ] try {; b5 d. r$ J' G$ G' `/ \6 N
sel = new Selector(obj.getClass(), method, false);) I. M) P6 F# s
} catch (Exception e) {
; u% e6 H. Y2 c( ^; E4 T: d5 t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 R4 H! H4 Y3 W + (obj.getClass()).getName() + ".");' Y' w6 S Q( I: T+ L. d) {% }9 C
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ F% K7 ~: w$ F4 A2 a# W3 X* g
System.err.println("The process will be terminated.");3 p. q( I7 w m( x
System.exit(1);
# O4 _% V7 @. M2 k8 B, ?: [) _ return null;1 W- Z9 G5 T! d" u) r7 w
}! S2 y( T1 }' ?4 C+ q! H) Z' C0 `
return sel;& p, G, b; z1 m( G, u) V
}
) Q; @- J6 C. h& Q7 r4 N& x! \ F( R} |