import swarm.Selector;
- D/ k/ g! N7 Z+ [: d
0 L& v* c" o/ X; L$ ypublic class SwarmUtils {4 ~5 L' F1 x7 b# |7 R. p! a6 \
public static Selector getSelector(String name, String method) {
) R2 z, |3 C1 G9 {% U [0 K6 P Selector sel;
2 v @+ O% A! v7 f2 ? try {
4 Z2 x1 J; \( `* V* I( R sel = new Selector(Class.forName(name), method, false);
$ ]9 C2 m- E* _# x } catch (Exception e) {# s; T/ x/ }' y/ O; i( x- Q8 H" s: ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( N3 _9 e I, I! a System.err.println(name + "." + method + " returns " + e.getMessage());2 j1 A3 Q6 p# t. A+ m; ?, a) ^
System.err.println("The process will be terminated.");8 F8 G9 d2 B8 h6 ?3 V( O1 Q9 \
System.exit(1);
3 |* r1 A: h; |- z2 w1 n, ~ return null;
; Q! O4 d) m5 { }
# l; L3 A# }' k6 ]" U# N, L return sel;
% r+ V, O' V5 f2 h. P0 k }7 O5 p& G9 z2 H- g; G: j( {- C
1 m6 E Y6 w7 z, P$ {1 G# \$ Q public static Selector getSelector(Object obj, String method) {
; o, s) I5 D$ H) I; ?' n$ j Selector sel;% V7 t e7 y7 \$ c
try {
( A, e- A; ]0 J sel = new Selector(obj.getClass(), method, false); M; \* ^( t5 t2 i5 g
} catch (Exception e) {
5 \8 k7 ^, R5 M8 W* u System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& Z: i: x" y5 h0 r; @0 w" { + (obj.getClass()).getName() + ".");
) o9 n4 O. a8 r+ z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: X& u! K; u6 m. D g0 J
System.err.println("The process will be terminated.");# A: O! D* z: R9 s! o
System.exit(1);7 g9 E, ]9 i9 R% w
return null;
+ J# {1 S c% J) M7 F c, D }+ N" Z+ \* }/ [" `8 j
return sel;/ m+ }. B& M% g2 J0 N# E: |6 T" T, l
}% }5 q1 J5 R$ S5 g" j
} |