import swarm.Selector;+ g8 X: j/ k5 r0 |( K; o
3 Z3 L- c" m! j1 j2 Qpublic class SwarmUtils {
8 a- ~5 Z9 d/ @% C public static Selector getSelector(String name, String method) {
/ K6 ^; |+ G5 v( Y) Y& o Selector sel;
1 ^7 e b, y& y* W2 Q- \ try {
$ p7 e/ R! a9 C% Z( m$ c& X sel = new Selector(Class.forName(name), method, false);
1 s; H S" }7 l! I/ X } catch (Exception e) {
1 h4 Z8 x3 _/ W- \ b! e2 i System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" ?% p$ ~0 z# g$ x; C
System.err.println(name + "." + method + " returns " + e.getMessage());
% e" e: j5 u' W3 k7 I System.err.println("The process will be terminated.");
! [- I$ v+ x: V$ N& G P; y System.exit(1);- a; M: d3 W2 Q8 l, U7 k& e: b' \
return null;
& F! E# a, J3 O( J a6 k }
% T# y& w4 _# v% X0 ` return sel;
" l0 @& S# ^. f; E- Y Z }1 z7 ?6 K8 Q+ |& J% C$ I9 ~
$ L+ ?$ D! y J5 @: L public static Selector getSelector(Object obj, String method) {% _1 l; D9 b/ d% W" p8 f* V2 H
Selector sel;
& }" f+ h# |. Q/ t try {2 j0 B9 u+ g }# d' X' j' n7 b
sel = new Selector(obj.getClass(), method, false);8 E; y8 }2 n& |
} catch (Exception e) {5 m- s* `, O- p) i
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
/ |# j; k7 `' [ + (obj.getClass()).getName() + ".");9 Q1 V" n% k& {2 O5 d, V- \
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());- P% r# p5 _) S5 [+ @* Q
System.err.println("The process will be terminated.");
" |9 r- B: G- h+ X System.exit(1);
, A4 E: u5 C1 f$ e" _ return null;
2 R5 n8 Y" G) l+ {4 _8 n0 q) @" f* [ }
7 d' b) j! }; R2 j return sel;
* e; Y. C/ A. V+ K0 n3 k }4 M4 j$ p2 s5 G- N! I: W( c2 T
} |