import swarm.Selector;
6 x! K+ w; V+ a! V" r2 u0 p1 _3 ?. W, l1 m0 Q/ l% E
public class SwarmUtils {) [' \5 J: r1 W6 b- c& c1 j
public static Selector getSelector(String name, String method) {! V: F( P ~: e! i7 c0 z
Selector sel;) Z5 U# e5 A9 U' a
try {) a8 b' T: G' `6 }+ _7 f/ p1 X
sel = new Selector(Class.forName(name), method, false);
& ~! R c2 Q+ W" i$ \+ S( D1 ^9 _ } catch (Exception e) {3 x. Y$ L Z( P" l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 `6 H5 p6 E, ] |) q( }. x0 r System.err.println(name + "." + method + " returns " + e.getMessage());& K/ X3 m) E+ X' J! V8 K
System.err.println("The process will be terminated.");+ P+ Y' n- W$ G& z5 T6 Q; j
System.exit(1);
: m9 G* }+ w& ?: F3 c; b return null;2 T6 E6 Z, y' A* s
}
7 J9 ?. m; j3 I/ m* c6 {' u return sel;7 a: }) y( R; u" S
}
" [- E( `) |6 ?& a. c
' H0 X q" w+ |$ D7 i! v5 o$ `8 [ public static Selector getSelector(Object obj, String method) {" R7 M! O( F1 q+ B
Selector sel;' l7 {" m# h1 e0 }
try {
# s2 O, m& h, ?8 _: w sel = new Selector(obj.getClass(), method, false);- j/ D# C/ @* x. G1 l4 G
} catch (Exception e) {7 N! q" j6 j0 t: c' P) j9 s
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ ^6 C+ [5 }+ j6 ~4 S
+ (obj.getClass()).getName() + ".");
! Q2 i7 f j$ N System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());2 g. S% j; K& i) C" y7 h+ i! C
System.err.println("The process will be terminated.");
3 c8 s+ _0 `9 V System.exit(1);
+ ?: [- P9 i# K$ y. U. }9 j4 ~ return null;/ T) _1 U- S) x% I8 N# Q. F
}
) k4 L$ e" U/ Z- _ return sel;
& i& M, T* I1 ^* _ }$ _$ {0 z; D% Y! i6 P! x% L
} |