import swarm.Selector;
% q% G1 H. V& [
/ D U. O0 n1 c6 Opublic class SwarmUtils {7 f' b5 B9 f/ {# D# }( P4 B& C. c
public static Selector getSelector(String name, String method) {8 \2 r: y i, K8 g3 P' F2 O7 P) i) e: m
Selector sel;6 n- a0 D* H- c$ r
try {7 D! ~8 {4 E3 P
sel = new Selector(Class.forName(name), method, false);
- f* h2 d& j7 x& x/ T; |" d5 i# } } catch (Exception e) {
9 A: z Y: R/ W# W% L2 V System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( M2 q) V6 x' Y5 [# u, z1 J& G( y0 {
System.err.println(name + "." + method + " returns " + e.getMessage());
2 \9 U# r. y3 N5 U2 V+ K7 _, Q System.err.println("The process will be terminated.");
( c4 Z' B/ ?6 D. t; f System.exit(1);
1 d" B: g9 N( q; V$ f4 h# E return null;$ s& @3 k1 k6 J3 ~& k2 o; ?6 V% H- K
}# y4 J7 h. v2 p; S/ ] Y
return sel;+ J6 S6 Q, R& U, Z. o
}
4 ~" T, T% R W4 a
1 e+ _& O% X/ n' f; R: b0 O0 m public static Selector getSelector(Object obj, String method) {: L3 m7 C. e+ |- \# R, L
Selector sel;' T4 F8 S p2 S: _ E6 A, a
try {
7 F; T' D1 S5 P' I0 b) H [' @ sel = new Selector(obj.getClass(), method, false);( J' u; j0 }, M8 B w
} catch (Exception e) {
5 w }3 n, t" Q& Z9 Q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 r1 z0 F7 ~1 H6 o- }! x! `8 m + (obj.getClass()).getName() + ".");
) a5 T% C- @2 b9 ~ |0 o2 {7 } System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ L5 C, C+ D3 ]$ [ System.err.println("The process will be terminated.");- e0 h, t/ O$ b4 K) R
System.exit(1);% `* _7 w2 s. z5 A0 ]& }
return null;
4 t8 |6 L- |# a8 i9 a1 R5 j }
' n: g3 _3 |/ w! C0 Y return sel;
1 R1 v% b2 f% g6 |' M& m }( N; X' P0 @% G- @$ Z
} |