import swarm.Selector;
4 t2 u r5 z) R0 U
0 B- g: G: Q) Z5 x5 d. {public class SwarmUtils {
7 i7 O; n- K: [, a* `9 ~1 p public static Selector getSelector(String name, String method) {
6 k0 j: g3 [ v8 q. y3 r. l+ ^( S$ {7 S Selector sel;9 m; x) s9 Q: j8 J: Y& J+ \) F
try {
. o# B+ L7 j! Y) R# l sel = new Selector(Class.forName(name), method, false);) X5 [% K' M4 J$ C5 s! z8 S
} catch (Exception e) {8 a4 U( e! k1 G# a/ l' d
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; E2 S9 V0 z2 M' J, [) P6 q System.err.println(name + "." + method + " returns " + e.getMessage());
9 g; x: P8 b: D3 g B9 }0 D System.err.println("The process will be terminated.");
" @8 h8 P. P. B6 T1 j& A% X System.exit(1);# ^1 Z- X+ ~ |5 o/ d' [- ^1 f" C
return null;+ R9 s. v" e% _
}$ l7 L% t% t$ P& b3 D+ d7 v, d: p/ {
return sel;- n( {# E8 ?! w2 l/ m" O
}
1 c/ @# [4 r+ a' d$ \
' k1 A9 { v' i- f% N. D; C0 {+ G public static Selector getSelector(Object obj, String method) {
( L6 u) Q& Z7 y5 `" [1 o Selector sel;
; S) X4 X0 M; K/ J0 } try {5 S; K8 B. T+ m6 p' ?8 {8 O+ T
sel = new Selector(obj.getClass(), method, false);
+ Z. B9 |: K& R% e& [ } catch (Exception e) {
; _* L" f8 G- c- g$ O' e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 l$ c3 ]. b5 {6 J# b
+ (obj.getClass()).getName() + ".");
2 F7 j+ z5 i% W1 |9 L! f5 ? System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 b4 A) b1 q, [3 E8 X J# f( b6 c System.err.println("The process will be terminated.");
7 c5 d# V/ U* q, X System.exit(1);
6 {( k8 u8 h$ `, a* J; n4 P+ O return null;
) y+ E/ I& ~! h9 ?2 i; q7 I6 { }$ r$ j$ F, e, j5 C
return sel;- o/ S) ~* R$ k: r. F5 V
}
! C Z, e9 `$ r: I} |