import swarm.Selector;
$ L' D! C, O* F8 o8 g$ _
9 S1 V) Q7 Q* b- mpublic class SwarmUtils {
' K& S$ v4 Q' f3 a6 R$ L public static Selector getSelector(String name, String method) {
9 X8 e6 X: M# k9 m4 I/ P4 w& i& N; k Selector sel;
: P$ l& ^( O+ ^; ] try {
" ]2 F/ d% Q8 @ sel = new Selector(Class.forName(name), method, false);
5 z) k' z1 d/ a2 O; ? } catch (Exception e) {
) t& k$ f+ Y' ]- w8 v: y. |. z6 U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
1 e' m" k% ^" @6 R: a System.err.println(name + "." + method + " returns " + e.getMessage());8 y2 \% { B6 }' j) {) B
System.err.println("The process will be terminated.");, V9 _' c% d }7 k/ j# c3 _7 R3 K% i: s
System.exit(1);
% S- t3 R; W8 d) F9 _' K: P) ~ return null;) }+ l8 C! o# a7 L) H6 |' |7 T+ h/ R
}- {% U& y1 m- D
return sel;- M( B0 @8 G T% I" S v0 t1 Z1 S
}
1 _; d3 S. I( q" `! @6 e6 p- ]- c2 d& ?$ y$ c, B% r
public static Selector getSelector(Object obj, String method) {, o7 b( F$ }8 N* q( r
Selector sel;
# O% z1 k+ _/ O1 Y# | try {
E! t! U0 V/ h sel = new Selector(obj.getClass(), method, false);8 \, E4 n7 C* O- r z
} catch (Exception e) {# u# b1 k/ U3 A; C! q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) N, @9 `1 y& |/ G( u& v- o8 b + (obj.getClass()).getName() + ".");
& N4 m5 v" Z0 L4 B U* l0 y System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());2 l6 E5 C0 t4 {( u/ |4 H1 G* l
System.err.println("The process will be terminated.");
9 }* {& y ?( y. `3 X# k! X1 {& k System.exit(1);6 ^" E2 R5 W' a {) O4 {! g0 M
return null;; V7 ^' w7 C; Z4 g( f9 E
}
: y6 g, l& @" b& M1 ? return sel;' X3 J& w K5 z5 R8 q# m" z: _
}
& R1 F" W* y/ H/ m+ U. j! e, [1 ^} |