import swarm.Selector;
$ d+ r' z5 f: T( |- B- A1 b4 M3 Y+ {- s/ W/ Y- Y1 D5 p L
public class SwarmUtils {
( F: C% c+ O- e+ Q9 x k- `+ q public static Selector getSelector(String name, String method) {5 q1 V" {% G9 s9 P( M
Selector sel;
9 x4 V% Q; B+ Q& V try {
/ }/ U! H/ S6 S) B3 t9 e% G sel = new Selector(Class.forName(name), method, false);( S- v3 P& {9 {
} catch (Exception e) {- [$ N2 @0 f! y- B
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& h1 d v- E- M6 s5 F0 h
System.err.println(name + "." + method + " returns " + e.getMessage());
' K2 H3 B9 z u" h/ u; H% h6 f System.err.println("The process will be terminated.");
]$ W" Q6 o. M- O, R System.exit(1);
/ D) S6 o: z6 z6 K* I* b q& q) } return null;
0 o1 I8 g% x8 V; C }
; j3 G0 r+ a3 K: F: Y return sel;
, K* |" B! Q1 k1 j }
, T, p' i) E. A1 Q, _" @5 T2 F) `9 C ]7 C& g5 G# Y; F4 v! y4 \
public static Selector getSelector(Object obj, String method) {/ \ a; O) u; E4 x7 E9 ]; T& |
Selector sel;
3 ~. k6 x# N) K" z: k try {
- M; u1 g, l/ Z; q0 o7 V sel = new Selector(obj.getClass(), method, false);
- F* z1 \# d$ B) k1 Q } catch (Exception e) {- R" Y% f9 T7 _) Y z: v
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ f( `# P% r3 ~/ H& A- F
+ (obj.getClass()).getName() + ".");
1 b1 I1 `1 v7 _# e% Y, e4 y& F8 H System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 y" L8 o/ U/ O0 ?' `" H
System.err.println("The process will be terminated.");
6 G) M/ D, O- e6 {3 Y# B! ^ System.exit(1);
) b" l2 M' Z. J. E; P$ m return null;
3 h+ |8 y F* P/ n+ E }
$ o4 ~1 o) P' ]* i! v; ^ return sel;
' P7 X! e# ]+ Z6 J! B* }: e8 E }
& U. l8 g. J! [' `- k} |