import swarm.Selector;& F( Y; b# b# ^7 m2 b, ?& _
! U/ u/ `/ j* S$ o8 h* {. Y8 Jpublic class SwarmUtils {6 r3 V; d+ u0 l) G j. j
public static Selector getSelector(String name, String method) {
6 ]/ I8 D* R! n$ P! \; Z {& f Selector sel;' e: @9 [1 c* O) d$ v
try {
6 }. b7 a6 \9 h; _ sel = new Selector(Class.forName(name), method, false);' b; N$ m2 _6 _$ w0 d
} catch (Exception e) {2 ]0 d' ]* l$ _3 |& P
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# N _ g% `3 e, U+ ~" K( `$ g& C System.err.println(name + "." + method + " returns " + e.getMessage());- v! U! L6 R# E" ~1 j- ]
System.err.println("The process will be terminated.");7 z& a* U4 ?9 s8 J/ E. [' S8 L
System.exit(1);, Q1 A$ c7 b: ~( G! A) y+ ]5 z, g
return null;
7 Z& f- M( V4 v" c+ l, ~, Y0 ^ }& ~( t* b# R: m. p( N/ b" ?
return sel;$ M4 V8 S9 j; _5 A' {. Z
}
1 W( p( h8 t- ^8 \6 s- R7 v8 G
* Z* Y0 `, j& y) s w" E public static Selector getSelector(Object obj, String method) {% ]6 d9 ~* C5 D0 D4 `3 L
Selector sel;
+ C1 v- ]3 _' `" z try {
) I3 Y) Z; i6 i3 H. D sel = new Selector(obj.getClass(), method, false);
7 s/ |1 [& t8 J! U: L/ ] } catch (Exception e) {
. G; }9 \# z( e& ] System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
/ [5 C2 v: F5 v + (obj.getClass()).getName() + ".");
0 ~9 M* ?5 v7 x$ R+ N System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());- q% n5 S% k) k+ @
System.err.println("The process will be terminated.");
$ W t4 i1 S9 u& } System.exit(1);
- D; k, Y/ ]! D3 S& U- r) E return null;4 P. A% Y4 ?5 E1 W
}
! d) _6 V' V% F6 M return sel;) Z- b/ Z- Z" f. g& @
}8 W7 G9 w$ `& }! R
} |