import swarm.Selector;. k+ M/ Z2 I; v' `; _6 v
; s. P, |! E8 O! B# H
public class SwarmUtils {
/ Q7 v( | J6 M( s3 K7 c) L* u public static Selector getSelector(String name, String method) {2 B0 ?, v; ]& @6 K2 K7 X! P
Selector sel;
; R+ f. L* R) z8 F+ |5 O( y try {
" J( n' z" X) ~( N sel = new Selector(Class.forName(name), method, false);' G: I* O) L; ], P
} catch (Exception e) {
9 M5 n. o7 ]$ U4 u# n9 S System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- b! h! r q1 |0 w* I
System.err.println(name + "." + method + " returns " + e.getMessage());
3 j6 x9 ^6 u/ {8 X0 U$ G/ e System.err.println("The process will be terminated.");
6 k& c1 [5 S( V: W7 ^ System.exit(1);, s% Z% ]$ n: g7 [ q
return null;7 {0 m6 a4 l1 i2 S. U8 k
}
% x' @! I: |) X/ ]( k return sel; u0 N* f2 z6 N4 \
}
. r5 O: ]/ d0 u0 A1 C5 o# `! n& z; }
public static Selector getSelector(Object obj, String method) {, \: \$ W; U, F- _6 O3 M/ N) [) u
Selector sel;: t, e7 G. j |$ D3 C; ]2 Z1 \
try {( j0 ]/ j! \6 l1 D
sel = new Selector(obj.getClass(), method, false);
) P6 H& Z8 a2 \. N9 y( j } catch (Exception e) {0 T3 p' n8 v+ t: f( q. E
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 L* R. E+ ^6 ~1 C
+ (obj.getClass()).getName() + ".");
8 Z7 m- k9 {7 v) z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 d5 b: ^6 z6 H9 G% \' F
System.err.println("The process will be terminated.");8 K! q) Y" N1 a3 E2 X! H/ u
System.exit(1);% |+ R! h2 J9 E ?7 t9 L
return null;3 ~: b/ M& q6 y, g
}( y" ^$ ~% Q- _7 U4 F! B% O9 K$ O+ @
return sel;
4 r% M* k; V( l% O }# {3 Y7 X: D: I0 ]( [
} |