import swarm.Selector;
7 s: {0 D$ y0 ]1 \& K( [+ P, _' F1 I
public class SwarmUtils {8 g& }% x: \* S
public static Selector getSelector(String name, String method) {% ^: r7 @' i4 Y0 Z' L/ ^- [
Selector sel;
8 X9 x) ]* ]$ Q' e try {& h7 ^+ `# U1 ~' u" s% ~2 o" q
sel = new Selector(Class.forName(name), method, false);1 q* @% H: t( f/ ?- @6 Q
} catch (Exception e) {
# ]# b" Y5 N, v$ F2 I# e! j6 w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 A, Q& g4 _( z! T
System.err.println(name + "." + method + " returns " + e.getMessage());
& x% J+ @. D `1 V% v3 r( ~! h System.err.println("The process will be terminated.");$ M! U3 t/ u4 i1 i" a
System.exit(1);& G# e, u. Q6 f- N0 |
return null;
* \, E1 o! P/ ` z5 E4 ` }% e9 b: ~! l& a" m0 K8 k
return sel;
, z2 g2 @! `% G# s }
( _- p8 q4 B. d) N E
2 `8 b2 Z% c+ y8 A public static Selector getSelector(Object obj, String method) {: F1 z8 Z2 b. n) d0 _+ \
Selector sel;
- Q$ s0 ^# Y0 x6 w' ]7 s3 S% o try {. N; h: s* m; }
sel = new Selector(obj.getClass(), method, false);
2 w6 w+ G e4 _0 o8 Y } catch (Exception e) {! e+ ?% v% a* c! f2 F- I! `6 g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ p7 O4 t- g D% e" k8 @
+ (obj.getClass()).getName() + ".");
, i8 Z7 { ^( M# m6 g1 i System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());- b4 W8 N8 ]1 J) f2 m
System.err.println("The process will be terminated.");
# L+ v: q6 D, [6 C7 \, U4 D System.exit(1);. n1 ?4 P2 R4 w0 U- L& a
return null;
5 N: Q L! ?9 {) Z/ l1 B3 S% @1 q }
- r% M/ b# C2 J$ ? return sel;
& B( A1 s7 j0 ~6 Q! j }5 H: _; T. Y# {& j% A: N$ z8 Z
} |