import swarm.Selector;
; z1 | p. J, w. Y9 Q5 p5 f5 w6 ]# a. u3 R" N; q' |, E7 d
public class SwarmUtils {
+ h r R# h; y' N public static Selector getSelector(String name, String method) {
3 b% I1 [+ Z) n8 q# w+ ^ Selector sel;
7 L/ B9 k/ _; H. a0 V- J try {
0 p$ [, f% \1 b! {. d3 J sel = new Selector(Class.forName(name), method, false);
7 k9 b; r1 `) m! Y* c$ L# j9 n% n } catch (Exception e) {8 o( D* c$ f4 a
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 o' w' G. z( W' f) J
System.err.println(name + "." + method + " returns " + e.getMessage());
: K# ^; k1 K6 L9 A# K6 u2 L* h System.err.println("The process will be terminated.");% d1 p7 I3 I+ H0 n& T
System.exit(1);, R: ?: a; F- Y# e. G2 v+ Z0 h
return null;
+ m8 Z: \; p' U0 @, z+ J1 b }0 n5 l+ q6 h- n
return sel;
$ l& w0 O' L9 M' C3 h2 z }
& }; w$ q% x6 s E8 p
5 Y5 J* k8 n- c" D public static Selector getSelector(Object obj, String method) {
: Y4 ~7 p$ o4 A2 E Selector sel;) Q) @6 k. o$ {$ o. G
try {/ `, G) |0 s: Q# c& M" p
sel = new Selector(obj.getClass(), method, false);
! _- d9 y6 ~3 V& P } catch (Exception e) {
' j' V0 _; z# v System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' N' c0 l' D( b2 R, |; @6 m) N
+ (obj.getClass()).getName() + ".");6 u- i: A+ O5 ~4 Q1 I7 G
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 S- W" ^- _/ q3 P+ V/ P
System.err.println("The process will be terminated.");
) Z# g5 S2 P- Z2 E9 y' W System.exit(1); [6 L0 X/ B! q5 y+ z/ B5 v3 N
return null;* ~1 u8 c0 I: ?8 c Z2 m
}( p+ P3 R) `9 L- y1 E, o; k
return sel;
! [ D: j1 n% T* }& ?+ q }3 a2 u* k( W- J/ V: a- t% \" l, P/ i
} |