import swarm.Selector;
/ `' s' v* K5 M5 r& y9 R5 y3 l9 B8 \1 H% [
public class SwarmUtils {" v$ j$ D7 |5 }3 a) b/ ~6 R* n$ o
public static Selector getSelector(String name, String method) {5 D9 }7 a$ V# \* k5 ?( D9 l" J
Selector sel;
: K0 @, C6 b+ R5 |, @: a try {! ?, T& {! S- ~6 X8 B: d# i! c6 x
sel = new Selector(Class.forName(name), method, false);
, u- Z) V" B; w, Z4 m } catch (Exception e) {
6 C' E4 f# i7 A" z W System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
5 \& v2 M" R: M g) o7 f System.err.println(name + "." + method + " returns " + e.getMessage());
5 B2 B2 o5 t* p, H9 {1 V3 H System.err.println("The process will be terminated.");( X/ ^% Y4 a: S0 x J6 T: E$ s7 ?
System.exit(1);
. ^# ^3 R: [+ p0 [7 r( }6 [ return null;5 H ]' d4 Z1 x- h4 k3 k
}
2 K; E5 `6 p s/ G8 S- U return sel;
+ U* u0 m0 V3 f9 J# J* A }
6 _8 i6 w. W$ Z: s6 p
/ f' ?4 R& p" j" n ^' R$ x public static Selector getSelector(Object obj, String method) {% w+ Y, i; M8 u
Selector sel;
0 O5 N- x# ^' {6 P# A: N/ n- ~5 I ^" F try {" ~9 b. Z+ A3 A6 i* N
sel = new Selector(obj.getClass(), method, false);( w+ p; L! v9 M9 I, K
} catch (Exception e) {1 N' F7 i1 U7 V. P2 L6 V+ o
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "( a5 V2 [( C5 \' u# P3 H9 E
+ (obj.getClass()).getName() + ".");
9 D& C/ N2 w$ z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 ]+ ]: f7 T: [5 L- t* ?/ S System.err.println("The process will be terminated.");1 k3 S7 q* b( |$ k1 A) v
System.exit(1);1 P/ W% S- F2 s/ O3 b5 p
return null;
7 m% Y7 v0 \* x$ Z, ]1 \. | }
3 [, q3 D" x5 W4 W& M T2 c7 { return sel;8 s4 s [! u. J% y
} f, y1 j& {' D1 m- W; V7 e5 Y" g
} |