import swarm.Selector;4 `& C7 r0 Z2 l6 d O. ]0 H5 [
$ g' b4 g" ?: |7 |public class SwarmUtils {
* x# q! L/ l- H( O0 F* } public static Selector getSelector(String name, String method) {
; W% l2 q j7 w4 h% S Selector sel;/ @& S' f9 G0 w8 P1 \! U3 Q
try {1 H& b9 d ?$ M$ J
sel = new Selector(Class.forName(name), method, false);8 Q j8 b% \$ r
} catch (Exception e) {
2 \4 J5 S, f" X* C& I. m, J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
2 \0 B8 ~$ ^, P4 _ System.err.println(name + "." + method + " returns " + e.getMessage());
' N. Y- z5 c+ y. W2 G% D( S System.err.println("The process will be terminated.");
! ^6 T+ U O# G# g$ Q% J M System.exit(1);
; B% l& ^1 a% @* W+ W return null;% Y' Z& [9 l$ u4 w' |3 {/ |! }
}
) z3 | t% O( U& A: \" K return sel;
$ ^+ A: _; \+ M/ V9 V }4 q+ }* o3 o6 w( S: x
3 |3 B* B' ]9 D; B+ z6 E3 B
public static Selector getSelector(Object obj, String method) {5 {" c: Z+ i+ `) i {
Selector sel;3 F( o% O) J y! L) f: l9 N
try {
# y% x6 Z$ ?% [2 R! s sel = new Selector(obj.getClass(), method, false);9 s6 o2 E6 I5 r8 U# d" R
} catch (Exception e) {* U; ^! U" \& r1 C z( S) d
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", E/ P0 C e) Z5 z7 B u3 M
+ (obj.getClass()).getName() + ".");
$ f. @6 q3 n7 U7 s6 E5 g9 R System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 S w2 K5 g9 J9 |# Z# \# j' ?) W
System.err.println("The process will be terminated.");; I) J! Z" ?% p. V, K1 I; W, f. |
System.exit(1);
8 B1 G6 q9 {1 B return null;
* F8 E/ ? N* F+ b8 Z; ?3 p4 _ }( Z x9 L7 W8 p, C8 h2 B$ P, u
return sel;/ r# g; Z. A& ?. J# b7 u0 n
}* u+ ^0 d: y" n" {. p$ W
} |