import swarm.Selector;, R- u& i2 H9 r3 t! E
/ B4 _9 `. p0 Apublic class SwarmUtils {
) _: c1 a' k+ c! R) j' T9 ` q6 B public static Selector getSelector(String name, String method) {% O. Y9 K5 H4 J* M' f' c0 q e: Z
Selector sel;
# y; ^' O4 s0 r7 m2 o( ?7 _7 ^% n try {' S. W. f0 C2 u( p, z. N7 r" q) I
sel = new Selector(Class.forName(name), method, false);0 C) @9 r/ m, u1 Y" P; z" K9 n" u3 K
} catch (Exception e) {
8 f; a% a" G) `& G/ {1 ]: } System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ p+ L( ^- B# F8 |2 v2 _
System.err.println(name + "." + method + " returns " + e.getMessage());
( q1 D. v$ O$ @- w0 L' x System.err.println("The process will be terminated.");
+ z; s- t& g9 V) A5 S System.exit(1);. a, V% |8 _3 s" H' B
return null;- K' l% }8 q: X6 H7 q4 B- g
}
/ m6 I6 M; o# v return sel;
5 R- @1 `* h! t( L9 j5 a5 X }* `0 F# Y. Z4 s8 {
8 \4 ?0 _" [6 p/ _) e. t1 E
public static Selector getSelector(Object obj, String method) {+ ~/ i0 O4 ^ f- i- c
Selector sel;" D6 Q$ |$ m* H* u+ J' W* s0 q K
try {/ i: s, a+ g- J F4 a6 A& R
sel = new Selector(obj.getClass(), method, false);, q% w3 G Z& Z6 f
} catch (Exception e) {
6 |7 l9 r/ m2 g System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
t) P- r7 `+ X8 g. P1 H( v + (obj.getClass()).getName() + ".");
F% s8 I1 V5 G3 `) v( _ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( v% J7 _7 x, t& ~5 R
System.err.println("The process will be terminated.");5 k( p; w8 W" ?9 d `
System.exit(1);
& U4 ?7 v; k2 ~3 l4 c3 p9 D return null;4 I& R! {. K+ W7 J
}! Y9 s* [3 C# F
return sel;* U2 r! m8 A, R9 d2 p# M
}
. `: J) e, W6 r( r7 a4 i} |