import swarm.Selector;
9 n' X/ X+ n1 a6 U# _( Z$ V/ M' K$ v2 m9 n$ H- r J
public class SwarmUtils {
4 E, g) [4 l6 M$ K1 B b( h public static Selector getSelector(String name, String method) {& Z' d: ^. ~2 z: o _$ w8 z
Selector sel;# G6 E( F! ?7 [2 }" h4 o
try {
- q1 n: ~, L! L sel = new Selector(Class.forName(name), method, false);6 n8 ~5 {; y) D' u+ v3 Q5 o, H, [& q
} catch (Exception e) {2 V* G5 ^3 X0 G; N2 a! O& `& `
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + "."); x, b; H O2 s$ z0 _
System.err.println(name + "." + method + " returns " + e.getMessage());
" K7 @8 d" j4 J" Z- J: ? System.err.println("The process will be terminated.");% Z9 Z& f% _9 |3 o' J
System.exit(1);
4 O4 n9 A `' {" P, @, s return null;
: @; D5 v9 v! _1 E }
$ x& K4 n* _% ]# ^& G. n% g return sel;
8 V3 R3 M( ?6 _, ~! Z4 | }7 W2 S' t! ?. l" j4 K
4 P2 r3 W/ O* W# N2 y
public static Selector getSelector(Object obj, String method) {+ [# o1 D9 H* r' ~8 s
Selector sel;8 h6 @1 t1 l2 K& o1 f: S1 ?# F
try {
% y1 Q" F' a5 n; n sel = new Selector(obj.getClass(), method, false);
" e; I! {0 z' C } catch (Exception e) {
% ~. L+ m- c5 A9 d! h O System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: U4 ? S; R' Y5 J. l + (obj.getClass()).getName() + ".");
* @5 a ~$ f5 v# ~6 V) q) {& V* B System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) d& ^+ ?( i4 S- O: K7 F: }
System.err.println("The process will be terminated.");
% }: T" v/ H$ Y- R0 w5 a System.exit(1);
* G9 F1 [' `* I! p4 t1 ^1 ]! I return null;
3 r* l9 o6 X% u, p2 a }
3 ]# a& t: W; j4 O# Y; Z return sel;
1 P& Q, T, b8 {6 d- c" J: I }% Z. ?6 o: K1 g( L4 x4 z! o
} |