import swarm.Selector;
9 K1 j# M* W$ |% r2 n' `: \* N( y
" Z4 A) Z% ?9 ~; {: }' Hpublic class SwarmUtils {, v# i' S t, g: R4 s& i
public static Selector getSelector(String name, String method) {1 k* A8 m( Z" P* e3 O$ L
Selector sel;# v5 k8 d7 x& J! F# t# `7 ?
try {
5 J) k+ ^6 _4 w9 k; {. R sel = new Selector(Class.forName(name), method, false);
, v: h9 |' H* m3 } } catch (Exception e) {2 u% ~3 y9 [+ D. Z% a" P
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");2 @ q8 X3 T) j- @
System.err.println(name + "." + method + " returns " + e.getMessage());
4 Y: @' J4 D3 w* t. d1 i" V System.err.println("The process will be terminated.");
d3 ~" Q* ?0 h) G" A System.exit(1);! G- v. }/ s6 t3 n( F! b
return null;
+ Z# p3 n9 q! g! L- Q# E }
$ l) S; c r: \& A# D$ ~, x$ O return sel;
/ h; \0 \. [5 Y5 K }( q1 H8 W+ h# |# i$ X1 o) p/ ]
m+ r! F" t* l4 c/ U9 O, ?# f' b! B public static Selector getSelector(Object obj, String method) {
\3 r* ~5 e$ z# E( Z' \/ |- Y- [ Selector sel;! ?! f$ J0 @1 w' ]
try {& J, s4 O$ v' i, }9 H
sel = new Selector(obj.getClass(), method, false);' b9 y9 N" O: }* b. b6 e0 {' u
} catch (Exception e) {
5 s& D* U4 o4 \ I8 Y/ B System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" |: F0 W' _3 X
+ (obj.getClass()).getName() + ".");' b- e! ]% B. Q& o V3 T5 X/ n
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- `9 s/ Q9 M( _7 S+ l6 _ System.err.println("The process will be terminated.");2 u$ q: h9 s$ H
System.exit(1);
+ S% f) W% ?3 `( p" r9 q3 z return null;
( x/ g" v1 G, w) m8 T }
# a& l v$ ?8 N0 T; v2 [ return sel;
! T6 |3 G- e4 W) V, c K& F( d0 Y }6 f1 n6 ^# G5 J, t4 f0 x
} |