import swarm.Selector;
3 [1 n/ K% { h" M# C% ~0 O4 X& c1 s% ~6 |/ i/ x% ]
public class SwarmUtils {7 X' N+ v! q- W6 N0 a+ l
public static Selector getSelector(String name, String method) {" B* X6 {- I- e. j/ }
Selector sel;" A7 N `( n) V6 }8 w" c: n. i
try {+ Y Z$ w. G1 b8 I: T
sel = new Selector(Class.forName(name), method, false);1 v5 q; Y( n$ z$ a$ x
} catch (Exception e) {
5 ]* a0 i) }% D E* g System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) a6 q" ?) ^; Y/ r" T) Q System.err.println(name + "." + method + " returns " + e.getMessage());; k1 i) m: q' H# J* g$ T
System.err.println("The process will be terminated.");# Q9 G- c# r4 X" H
System.exit(1);" F/ @& b$ _& Y% m7 `8 A5 W5 [1 H
return null;1 N3 w% X9 [1 i4 O
}
) K ^- {8 s( t! k" T: Y return sel;& z- s! B1 n; _3 X
}
- Z8 [. z/ `8 ?) ]" ]5 P* a1 z2 B7 V2 E6 T. _0 A: ~8 l! o
public static Selector getSelector(Object obj, String method) {) j' z: s# ?# y6 R
Selector sel;# E+ x1 l# w5 r: ~6 s8 F' W+ m8 J
try {: {* s/ ^9 Z: C# P
sel = new Selector(obj.getClass(), method, false);
$ y% B7 ^: t- S1 z: h+ [; @ } catch (Exception e) {; F3 p4 T4 S+ v& W. a" r9 a$ C
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
/ A' a& G" f4 x8 P. v + (obj.getClass()).getName() + ".");) ]; O8 {% x4 K& u' o
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: q% K) L2 P. I' A
System.err.println("The process will be terminated.");8 p9 S$ l- Q2 J
System.exit(1);
- n t! P' M/ W% I2 @ return null; D& R) ^) x: U4 f
}
8 j/ m$ K9 ^9 D% `! ]: e) y return sel;
# ]; a2 ?% d# j6 V) o }' j( z+ {6 f2 {/ z( v" f
} |