import swarm.Selector;
U% a! S& Q9 o! G1 G7 E
8 }* t! ]9 J1 y! b0 Upublic class SwarmUtils {1 T. E& V2 @* T W/ C0 Q
public static Selector getSelector(String name, String method) {
) J% A. w1 x8 w% z( B& J: t$ n& u0 s Selector sel;
4 F$ p* G) i0 U/ B2 ^6 `/ V/ q, A try {
8 C6 p2 B1 k% ~ y4 s0 [9 v sel = new Selector(Class.forName(name), method, false);5 x- w/ w: n; c; o8 Z- a- s
} catch (Exception e) {" C. |0 }, h5 n1 q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; l2 }. t3 g! {: R) g7 g5 O
System.err.println(name + "." + method + " returns " + e.getMessage());4 h6 G$ V7 d) G: `$ _$ w
System.err.println("The process will be terminated.");
b+ v/ E& ]# |; [( @: H System.exit(1);% J! `2 ^) c% F5 ~
return null;& s0 G0 U! I& R* F$ Y9 F/ ^
}
( O$ N2 R& H `$ R# a return sel;! _( r" q8 W4 s: R! f
}$ D, ^" x' a/ a$ g3 n
, b) A. A$ _8 o F public static Selector getSelector(Object obj, String method) {$ t5 K3 P. z" k8 U0 j; E! S+ D# `8 N# c
Selector sel;6 m8 j% |: w" ~! ~$ I
try {8 _" O* d* _ B" f# A
sel = new Selector(obj.getClass(), method, false);0 ~6 ]) o" P% l. S: K+ ~
} catch (Exception e) {# u- v+ j, W$ _
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", R0 o- R7 h" K3 m! @$ [# @: F
+ (obj.getClass()).getName() + ".");
* \; L: P- L* I ]: R. d System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 q" ]8 }2 P) r2 P( J" n5 ^
System.err.println("The process will be terminated.");
7 Z. ]) Y* E4 q7 H: { System.exit(1);
* Q1 v+ }& _( V4 r y2 o! Q return null;
/ W4 ?) \/ m% Y3 k! u }. q" p3 j6 M! M0 ^( w. m$ g* ?# Q+ r
return sel;
7 E! W9 [: j+ ~0 S }
* s. x& \1 v# m} |