import swarm.Selector;& q- B! u, }' l( x+ P" w: [
% d2 v* ^3 T5 f; L5 bpublic class SwarmUtils {
* u- U/ S$ j8 u0 d; I public static Selector getSelector(String name, String method) {
5 X9 O) h5 a9 c& A- i9 D: j Selector sel;
A+ \$ T J- w- W. g try {+ S" L0 A& d& o3 K/ P( z* A/ K
sel = new Selector(Class.forName(name), method, false);* z; Q6 s$ b) Z) @$ x7 r
} catch (Exception e) {8 G3 T9 w4 N4 U7 q% S
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
/ L# A" k3 n) p( b System.err.println(name + "." + method + " returns " + e.getMessage());7 A3 |" E( f7 w
System.err.println("The process will be terminated.");+ O3 y: y* t2 s4 W; g
System.exit(1);
& b8 o6 U% y9 Z2 ` return null;4 X" D1 `/ _8 n' s* y+ Q
}& |% k3 l0 X, b7 \
return sel;, v9 k: d/ v! n0 Y3 H2 T; m
}
4 }7 w: Y' Y( n: S' Y$ e, |' x; e. e3 w* A
public static Selector getSelector(Object obj, String method) {
& W; z) k+ S% }# t% h Selector sel;& @3 R$ W& m0 f0 d
try {
/ C, z) M. I* t6 m2 e7 O; C5 y sel = new Selector(obj.getClass(), method, false);" n5 K: Q" g3 }+ \* ?! A2 h, X. l
} catch (Exception e) {
5 R8 J2 n( |0 Z, \1 V" f( k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 }0 i+ G8 K8 x' R; p/ q! D + (obj.getClass()).getName() + ".");: {3 E8 Y% E# m: N
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 P3 ]. I8 W* V# o" x System.err.println("The process will be terminated.");1 ]! q0 {6 B5 S5 }, n) W
System.exit(1);
3 i& A* j y5 l/ T3 B return null;3 G/ X7 }3 Q2 ~! u5 H
}
g4 a0 D% m# h2 S return sel;" s5 l0 r2 r: n5 q, ]) e$ i" i
}! P/ ~/ E6 x4 |0 A0 |5 y
} |