import swarm.Selector;3 T: n" h: ]. w% Z3 o3 C
! s r0 K! r3 ]
public class SwarmUtils {6 l8 a. e* e- b! f
public static Selector getSelector(String name, String method) {
% a* i( f5 J3 G% ` t) r Selector sel;
/ {. } }: u6 {3 d3 ` try {
( t8 e: Z& X7 B. n0 @& {: [$ j sel = new Selector(Class.forName(name), method, false);
. @5 ]3 Z1 w. S" V6 r. v } catch (Exception e) {# V8 ^8 ?! J: y$ M0 F
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
1 b1 g, o: v# G8 n- | System.err.println(name + "." + method + " returns " + e.getMessage());
' Y2 u: H, }6 }- X- M System.err.println("The process will be terminated.");; _) X6 Y/ A7 {7 x1 g5 c1 d
System.exit(1);
) ^+ N2 d3 y- W! S; U return null;* t1 d Z$ G4 d' y7 B# l
}5 @6 K1 F4 Y5 m! w
return sel;: c$ O% I6 ^5 X$ J
}
0 D( v: M3 \/ k6 k2 }
# {% j+ a a/ ~/ l8 L3 S" ~% Z) Z public static Selector getSelector(Object obj, String method) { G& R, P ]$ Q& N- u! e* j
Selector sel;
0 J# N4 N( w( a* n3 p$ `( Z5 F! y try {3 T. }: | z) u5 [
sel = new Selector(obj.getClass(), method, false);. K* ]& Q: b. B5 j
} catch (Exception e) {7 c+ e4 O- L7 U9 m& V. i! r3 Y7 u0 W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ j" ~/ ~1 w& _" D0 P, k + (obj.getClass()).getName() + ".");5 n$ \; H* }0 q3 Q2 L
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) ]3 z2 O' m0 `. Q' G+ X System.err.println("The process will be terminated.");
- [: ` B1 K* m) D' c5 | System.exit(1);
- X/ z! }6 m9 l4 q; R return null;
3 |! c! U# n) y1 y4 S6 S! g" ` }2 M: r$ F$ V8 H0 ?( @
return sel;: `# l& o" E8 Q" f
}
- x% q7 O0 L* z9 Z m( k- i} |