import swarm.Selector;
+ w2 \( W- v- Q; @. \9 j* }
8 s3 u* W; M4 k& i$ m9 _public class SwarmUtils {. F9 n; L& s% w; A& N) x
public static Selector getSelector(String name, String method) {
& c5 C5 L1 k) t& ^ Selector sel;
8 I! ?5 T( S8 M9 t try {
* L, P$ N; D5 }% x sel = new Selector(Class.forName(name), method, false);5 N/ {9 `! N* _+ f: n
} catch (Exception e) {! O4 O& \5 C8 J" k+ Z1 y
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 R; \$ A1 G, r& ? T
System.err.println(name + "." + method + " returns " + e.getMessage());
: D: _. ?% @4 S& ?6 i System.err.println("The process will be terminated.");
8 C- B. C4 K' w. }+ Z9 g5 E0 u) F System.exit(1);9 a3 J: W& j. x C. W7 m4 u- k6 C
return null;
8 h( j9 w9 i6 g+ P& D+ E9 I1 T }) y8 G" _& v) G% Y$ K) `8 a
return sel;
8 a; B/ ~9 M" e0 G& Z, [1 R3 z* X }
5 ?% C# n& N9 d& Q4 t5 g' ^% r
. c% F, a2 |3 D. l( g4 P! B$ L public static Selector getSelector(Object obj, String method) {
3 r" @) @% j& X. F8 B3 F$ ~# F Selector sel;! v5 i" s3 Z* C0 |8 c
try {
6 {& @& c# A6 K5 d/ _) R2 T5 l- Z sel = new Selector(obj.getClass(), method, false);7 `. f* o/ \ W2 V; b# d& R0 d+ Y4 z5 h: f
} catch (Exception e) {
* r+ ~4 \3 a) p2 N: u0 _ @ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "- R6 t3 n0 _4 p3 C2 V& l U; U2 P
+ (obj.getClass()).getName() + ".");; i' g( T; }: [% B
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. l9 k N: k2 K& l" C7 |0 }
System.err.println("The process will be terminated.");# x# S" d2 Z$ z% d2 W' ?, M
System.exit(1);5 ^: w( k2 N: T& n
return null;
9 w0 S9 y. L- D3 G- ?; I }
+ N1 L& g5 S* r. t$ M return sel;
! W" i- s% q% L1 S* W/ \2 b0 a }1 k$ m$ K" q7 _# n. ]: D) N! b
} |