import swarm.Selector;1 o. W# u/ p* ~6 V# Y R
4 p5 d! d3 v% U8 ~" }4 Gpublic class SwarmUtils {
0 c6 _; e; X5 |0 y5 K public static Selector getSelector(String name, String method) {6 y2 G0 c, e: i) }
Selector sel;
6 D4 l# {; j D7 O try {
1 Q, L2 C. ] H" W4 _7 x9 R8 a1 r# I sel = new Selector(Class.forName(name), method, false);) |6 |% |, q4 |: b! |1 f. t5 {' l
} catch (Exception e) {
7 v* V' j+ K6 ~ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ U: ~* E6 P' J( n6 [7 R System.err.println(name + "." + method + " returns " + e.getMessage());
& a9 }' P& C& b8 V5 y' n System.err.println("The process will be terminated.");$ c5 D _- ]% J4 m& l
System.exit(1);
; r2 H2 C8 a0 z6 q return null;
9 _6 p" r/ l/ F: B$ d {' p }
1 w* b$ Q i+ x; ^ return sel;
# ^8 [ \; j z8 n4 ~1 G% A: j# O5 O } T9 K4 w4 h. F1 H2 F6 W; I9 T
( O4 r1 D& ]9 R8 U* N- c public static Selector getSelector(Object obj, String method) {
% a1 m4 T7 G2 w Selector sel;
3 W; Q, N1 \2 v try {
# Y5 M) W1 ^+ _' n/ x- x' c5 _5 P$ q sel = new Selector(obj.getClass(), method, false);
* l$ t, l* d% l1 y } catch (Exception e) {& d! `5 a/ k" x9 K: ]+ r4 C
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 u" }7 s+ b/ t' X5 [4 ~
+ (obj.getClass()).getName() + ".");0 P" u$ Y: |) c& l! Q
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. s9 {, {" h6 d; `9 R) |& O' q5 w
System.err.println("The process will be terminated.");* k5 S& c o0 I
System.exit(1);
P# u0 y1 ]! Y6 N) {% \: A return null;
! U. B+ N- X! A& g" p& B( {0 ] }
: Z' C8 b+ s! k' L# M8 d& Q& _ return sel;$ }" g/ x0 Z& M( Y. r. L
}
X, _" }4 e- u6 d" U} |