import swarm.Selector;
& `0 y( O' O! q5 j7 D
' ?4 s5 V6 P" Fpublic class SwarmUtils {! g$ G! m D2 ]: k
public static Selector getSelector(String name, String method) {
8 R5 h4 g! Y" M; E; F Selector sel;
( h/ E- t, }7 z4 z K% X try {4 \) S2 D- _5 ]4 j1 y% z* w4 l
sel = new Selector(Class.forName(name), method, false);
! w& S) j5 J# G4 e } catch (Exception e) {& J- G T- ?: h; k- X, f$ \
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( d' I1 f- C# |. u/ R+ ^9 j) t* z
System.err.println(name + "." + method + " returns " + e.getMessage());; c) {: P/ n8 ^' a% J
System.err.println("The process will be terminated.");
# f: J) `+ z! b0 R; Q7 X q System.exit(1);
$ [9 e e9 {1 }: w8 @# v return null;
) O4 ]2 g* |7 d0 h }' o' ^2 V% _. a) e
return sel;
8 |+ q/ `& ~6 x }0 a9 t: D7 C6 V$ x" l
( \( S3 s/ a, I8 x" j public static Selector getSelector(Object obj, String method) {
. N- _& U8 {, o/ Z w* p* { Selector sel;
- C& s1 ^1 W, C- l/ {$ w' R/ q try {
) {8 A+ X7 O2 v; }! b! C sel = new Selector(obj.getClass(), method, false);
5 w5 s0 a R( Z) l0 Z7 t } catch (Exception e) {
8 p" B, ~" J- u* m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& E l2 S. p$ {4 W
+ (obj.getClass()).getName() + ".");& ]' v5 a4 F& b0 E* ~
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, V& r0 _& k8 ]* s# ]
System.err.println("The process will be terminated.");9 A, t* m5 f8 f: w
System.exit(1);
! ~1 _9 F; U* q7 ]7 d! @& J" m& T return null;* j0 M, a( v( W7 o. t; h3 y
}
I; ?8 t* Z" T return sel;
0 O: {: b3 G9 [ }
% h$ L3 m6 _* i% h3 k9 `0 e} |