import swarm.Selector;
( l j# ^7 L" P* U% K$ W
( p8 o0 K6 H, b; f kpublic class SwarmUtils {
+ Z% v8 s6 ]$ _- `% ~ public static Selector getSelector(String name, String method) {/ v" |3 a( T" `2 ?
Selector sel;2 m, f; V/ R# L% J9 w5 u8 c, y( \
try {% m3 p2 [: A! g2 x5 z% g$ e, X
sel = new Selector(Class.forName(name), method, false);
6 C7 G( G! N+ y" I9 T } catch (Exception e) {
$ _0 A2 k. R8 d3 B- _ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* A3 E. H: _" Q: J, \, }
System.err.println(name + "." + method + " returns " + e.getMessage());' a- w g: G L- V. I$ y* t# c
System.err.println("The process will be terminated.");" ^) ]0 h: |( t- v
System.exit(1);
* _, G4 \) f' ?! @ return null;% E: Z7 K; n' C+ K7 r: C p8 L: `
}" b' A# m- \( b& e
return sel;
! O) j0 a+ e/ o, L% ^) l }( f' Q9 T- s: r# n0 p9 M
+ s4 |+ c" @6 S; @$ |6 Q public static Selector getSelector(Object obj, String method) {
- z* P' e! ~2 D, \1 o- p Selector sel;' L1 } v' D# F# o( b* R9 V
try {% u$ p& j3 @. B1 U
sel = new Selector(obj.getClass(), method, false);
2 T+ o5 M. |- z' K } catch (Exception e) {
3 s. R5 \0 S" c+ A) X System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% t7 M% s5 A1 f& ?6 f + (obj.getClass()).getName() + ".");
) P- B/ k' d0 a. \$ L$ w5 s System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 @6 d$ E# O L4 U4 e4 [2 ` System.err.println("The process will be terminated.");
- d+ w0 b/ H6 O' b0 `: D8 ^ System.exit(1);
/ ]6 r- i2 F, U8 |0 r5 N return null;
# k) Q \; {: e0 b* Y6 C }% _1 s# F, l5 l) z; F7 u8 v
return sel;
( X& [% i# b% D7 u: V' R* ]; | }, |4 r3 V( C4 j% Q& k0 O
} |