import swarm.Selector;- N; q. q0 z0 c$ y5 m& [
. E% I l9 H) a* I
public class SwarmUtils {
3 p7 ~4 q* t, q# U public static Selector getSelector(String name, String method) {6 a6 H& g; w/ r' \
Selector sel;; j( T. a6 ~ l+ N5 I1 j
try {
* I' D6 V2 z; M* T: m3 o sel = new Selector(Class.forName(name), method, false);0 l u1 c! N4 j+ V( C5 h- D2 Z# u5 _" m
} catch (Exception e) {
( ^% P0 n5 Q! H. E: q9 p System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& ]" Z9 n2 J3 p, i
System.err.println(name + "." + method + " returns " + e.getMessage());6 B# [ a0 F3 R1 I( Q
System.err.println("The process will be terminated.");
! I9 U+ F) I) D J System.exit(1);
. L% _% L1 B8 R' }9 ^ return null;
/ x8 J% k* w6 D6 p3 S& V- m }7 ?( X- M- k9 V3 W1 ?
return sel;
- L, {; C$ Q+ ]* o$ i6 v& W }
9 [+ v, F/ v, R: L' L8 M! Z
, Q8 @1 P# K) f public static Selector getSelector(Object obj, String method) {
6 e, c. b1 j' B8 k, l Selector sel;$ p' E7 }' ~( X) o# f) O9 G
try {
% p; e5 r% @- j9 k# m8 R3 w sel = new Selector(obj.getClass(), method, false);' X4 {0 p* q+ {+ o( i; G- y
} catch (Exception e) {3 f( P2 G# B8 w
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ F" y6 C* a _: j' c6 ~
+ (obj.getClass()).getName() + ".");2 d2 x9 W3 C7 B' {' ?! O
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* [. f3 l: m, x$ J0 v) V. b1 h System.err.println("The process will be terminated.");7 n) D5 J) r9 w, N( a- D
System.exit(1);2 F4 T) J6 I; K' S, y4 o
return null;
u' f4 L1 h) [& T3 C }) o3 l$ m0 E! t: U
return sel;
' K+ H. A& x) Q' M }
9 _ J8 R! y8 B5 n} |