import swarm.Selector;; J( X, }: a0 H1 M" j
; a$ ?% z; @2 w# v. \+ s) C4 qpublic class SwarmUtils {
$ s3 H1 y9 e; k# O2 w public static Selector getSelector(String name, String method) {
0 G# Y! \; Q. p6 [+ |+ h Selector sel;; E. e( S) [4 {# X
try {
$ L& e7 ?/ x0 O9 m* F sel = new Selector(Class.forName(name), method, false);
% k5 h: _1 G$ Y0 ~/ N7 w } catch (Exception e) {
6 p- D% m4 A) p8 y1 \. n System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");% f2 o, r+ B% o+ |
System.err.println(name + "." + method + " returns " + e.getMessage());
% ]; T# B# Z6 p4 w! L( V$ g: P b System.err.println("The process will be terminated.");
% f& q% b& z; Z& j System.exit(1); U$ L6 f- k5 J5 f2 S
return null;
, c9 }' Q- i2 c u+ ?! z }. D& }: t1 w) W6 I* t8 g: ~
return sel;0 V8 B" R$ Y% v% |$ M5 s3 z+ ~
}( Q, M4 {; q& m; f+ B7 G' {6 G
8 d& ]* u' w( ^7 _0 A! W public static Selector getSelector(Object obj, String method) {
4 `# ?9 O# i, } Selector sel;
: z; X2 W3 V6 E$ w; i7 J try {- J, ~1 c. N# H. k
sel = new Selector(obj.getClass(), method, false);
/ H" r! U6 h: c2 { } catch (Exception e) {9 B$ {5 S" D4 H* ?. v5 |; ]3 [
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "( i7 S( r, C6 R# G$ W# m8 l4 |
+ (obj.getClass()).getName() + ".");
8 V3 c- `9 L& |. I$ f8 d System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( u* K! C+ S2 g& W* s System.err.println("The process will be terminated."); L& w5 P. I& D( |
System.exit(1);
- f( G8 L5 A9 b3 S- l+ u return null;$ \* i6 z) S4 x- l& B2 \
}9 I" M2 G9 E) Z4 N
return sel;
# n1 t; n: c6 ?4 S }
5 W/ {2 b. A5 h6 y; d7 M& z} |