import swarm.Selector;
) P& ?& K7 s3 l# G6 h) W8 B0 c
/ E, e0 b% Q! j* gpublic class SwarmUtils {
+ C4 Q% s/ M" X s7 ` public static Selector getSelector(String name, String method) {0 E1 \( s- a F* m$ v) A/ k/ P& H
Selector sel;0 m, u9 c9 x- Z& D. u0 ~+ X
try {
. ?4 P3 @$ Q- u% d3 P V8 U sel = new Selector(Class.forName(name), method, false);
. l$ g1 w& w" N' x$ {: S* z! e0 |. a } catch (Exception e) {$ Z9 N' `6 H G
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ t9 S$ F, n5 l; l H5 P% F, U! A; U) M$ Q, |
System.err.println(name + "." + method + " returns " + e.getMessage());$ u8 M8 {6 b5 F1 B
System.err.println("The process will be terminated.");
7 C; s$ Q0 m7 L6 z8 L System.exit(1);
3 D6 B5 H+ \0 v4 O3 k) X j2 A5 t return null;0 I7 T: |' B7 K
}
+ X: w* L1 v3 Z1 N# y8 w% K: ^: F return sel;
: o, ?, y, Y( q) Y& H2 z3 |$ R }
, J! R+ M1 g- |% s* P1 O
$ b( R: N6 G; B h6 W; N4 d public static Selector getSelector(Object obj, String method) {# Q- ], t# o9 d( u$ s
Selector sel;, f/ O# D( u# D- F" c' O
try {0 ?% G* J' a* c8 _
sel = new Selector(obj.getClass(), method, false);" j9 d5 H9 Z* f& I2 K9 w
} catch (Exception e) {2 G% L8 C2 h8 X% {
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# Y$ }" k% F- e- g4 I + (obj.getClass()).getName() + "."); p$ y/ H% d6 j3 Z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- _( M& ? ~* e8 e+ I) e System.err.println("The process will be terminated.");( D6 n3 N5 r% @8 \$ [, _: p
System.exit(1);
( x, M8 l6 w' A5 }0 g( | return null;
7 e) o, \& H* C0 M( I' L' g u }( O o+ B3 q# ^8 F6 }/ W. w
return sel;2 S% o# }2 x$ `% U+ V
}
. L. \* r" O" u' L1 I} |