import swarm.Selector;+ v& v2 v' H" C5 W3 s4 s
: W+ T: ]& T3 Y w' [3 V% x4 S* q. D- qpublic class SwarmUtils {
! H: j4 g5 s* C0 V public static Selector getSelector(String name, String method) {
( W( h& v8 U+ F+ N4 x1 ^ Selector sel;$ [- y; J: p* V0 a3 I2 P6 z' y7 ~
try {9 d' q" L2 F2 u3 N
sel = new Selector(Class.forName(name), method, false);2 }1 Q( i; g' c* m' I% q" Q# ?% v
} catch (Exception e) {2 R& n% f' v* y$ _: _( k" ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
1 @! D% [% _: h$ x) G System.err.println(name + "." + method + " returns " + e.getMessage());
( N9 f" r) h) o1 B# d5 C System.err.println("The process will be terminated.");9 D8 n, P1 _. I1 D) G2 f
System.exit(1);) B3 B6 [6 o, k5 S+ t, i
return null;
& G$ N. K8 {0 P6 c! I! ?$ y }
- z" j( W/ V2 F4 K& i A5 [% h$ e7 {* H return sel;
8 @1 f8 q! R* B }1 g$ F' X! t |5 p. l
1 _" L2 x8 C/ r) y. H public static Selector getSelector(Object obj, String method) {& Z$ U) K$ I3 ?# U3 j" E: w0 \
Selector sel;. v5 ^& x1 w- {4 A- Q
try {
# b) g1 y% u' u) h( Q% P! Q! k sel = new Selector(obj.getClass(), method, false);# J# `# d% ]* z1 f$ f0 V9 o
} catch (Exception e) {# ^& z# D5 o' C9 Q. R; P6 O7 @
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; f$ f1 u& O5 A
+ (obj.getClass()).getName() + ".");
6 z4 A4 r3 i& {6 m System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ \$ f) y4 `4 S7 H4 {# K
System.err.println("The process will be terminated.");
. @6 x: g& ]; w, G) `- `- Q* L System.exit(1);
2 m7 U- e1 D7 k4 w- I/ g return null;
# F+ L& D* o! v# W }5 e0 h' O2 n5 |9 D& c% R
return sel;
2 ^8 V3 D1 I: H- t( W }, A7 B0 ]& j, }! v/ a
} |