import swarm.Selector;
! C/ U- d* W: J& o" a3 y ?2 W+ w7 i" n0 d; D/ r; n: w
public class SwarmUtils {
7 c( n' V" @1 ~) f: o# D public static Selector getSelector(String name, String method) {6 [( H! b, v5 T/ `( l# q8 K# l# N& B* d
Selector sel;; l* [( {8 g/ o+ j% a% d. ]
try {
N3 @; n) \' q& p. R" g sel = new Selector(Class.forName(name), method, false);
, C. P/ W, I% a3 y5 ?2 G } catch (Exception e) {" v5 l/ o. c/ y. L) a3 B( W- e0 b- t" F
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# l1 ~- o( F+ [! O9 I6 M3 J6 u: r* H System.err.println(name + "." + method + " returns " + e.getMessage());2 R0 M0 T6 d: b+ N$ O
System.err.println("The process will be terminated.");
( X- y6 {' @0 ]6 G2 A1 [: _ System.exit(1);
- {" a1 L" j- i" M8 q) a return null;5 u' n# Y, A+ ]1 [8 r1 O3 g
}" D0 m2 ^2 i! _/ J7 U- Y. _
return sel;0 o1 o/ ?7 f3 A; Q
}
9 ?, c0 ^% [, ~; Y i' F5 Q! Y- |: `4 R. Q7 q: Z/ u
public static Selector getSelector(Object obj, String method) {* T6 }. Z9 e2 K$ ?1 C' N, G, |/ d
Selector sel;
2 X4 i3 z" Q" I" L+ B& r/ p. u try {, f1 G1 b( [; k" |4 [8 w: Y
sel = new Selector(obj.getClass(), method, false);
( j' c, e5 q+ k9 s- u } catch (Exception e) {
: j; P) x: Q) } System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 t5 _6 Y! y/ {" K + (obj.getClass()).getName() + ".");4 X+ N' t1 v) l, a& Q. Q
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 ^* T1 Z. O+ t& J6 u) C2 W0 J
System.err.println("The process will be terminated.");
" E( B$ M% h0 Q2 s System.exit(1);+ i8 M! a! F4 ~' P4 _3 M$ f, |) T
return null; }) D% U8 m3 ?$ o. ~# M" @
}
+ g$ }# D) N+ e return sel;/ G K! t* l8 J! f$ _* m
}% |) M9 o5 k) p! [
} |