import swarm.Selector;
2 x# G- W- j+ i/ S2 O3 N1 s
+ d) k4 B, k/ I1 d/ ]public class SwarmUtils {
, R' D5 A4 i5 t9 [) U7 ~ public static Selector getSelector(String name, String method) {
6 A+ p h# r3 `# E9 B# A5 G$ G Selector sel;
' V$ P: |+ {6 Z* c% B try {" _& _" m$ d4 G% O( `" [
sel = new Selector(Class.forName(name), method, false);* e; {2 Q! W6 E5 B4 D7 u' n( @2 Y
} catch (Exception e) {
2 O1 S6 o; B% [% b4 A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" c% e- j/ r. G1 h
System.err.println(name + "." + method + " returns " + e.getMessage());
' \% a. ?- K1 E' Z System.err.println("The process will be terminated.");
; x1 ^; ?6 s6 c7 D System.exit(1);9 U+ F) E5 F4 q6 _3 ~$ r
return null;
4 F- p) K6 E8 T3 `. m/ S. l( J }% @* K& D# T' _
return sel;/ O' w: J# [2 T( b* w
}
. V3 i( V# [1 M1 ]* F; L4 _
3 S3 ~7 e3 ~! s- X3 n* y# y% Y public static Selector getSelector(Object obj, String method) {
& T# C7 C* C& J$ }- A! F7 K Selector sel;
& `1 z! I# x& X* x try {) Z& J a/ Q; ~# e2 W/ J$ z' h0 F- w
sel = new Selector(obj.getClass(), method, false);$ p/ ~7 A. ?1 @
} catch (Exception e) {! i1 O' C$ b5 a2 V
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 R. @& P4 P$ Q4 y2 V; p$ K' P + (obj.getClass()).getName() + ".");
8 h: A C1 c; `) }4 r" @% c# V: r System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: c" ]; G6 T t$ A, ]9 J System.err.println("The process will be terminated.");
9 Y2 K5 _% f7 O1 ^6 q System.exit(1);
& @, ?2 O, t+ z: Z2 \6 B$ D return null;! \& b) ` r# X: q4 a" r: H7 H) D
}: D5 [6 W4 m' q: f' P" `& O
return sel;
" @; a+ n9 ^2 _" b- l( w6 j# y }2 d3 Q& v' w: m7 |- z
} |