import swarm.Selector;
8 `# A4 b Z3 m% |( S. y& I. `! \" f% q: J* I9 ]# a3 J& M
public class SwarmUtils {; ^: O% {4 I8 X+ o
public static Selector getSelector(String name, String method) {
. n3 I( a2 b/ L6 `! N. Q0 _- @ Selector sel;
% Q( a" R a' ?2 d try {
" u6 N. r4 H; I# c5 k$ T sel = new Selector(Class.forName(name), method, false);6 l N9 Q' z' \1 y
} catch (Exception e) {$ U$ R8 c( I/ T( ~' Z' W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) ?2 \' O# H6 } System.err.println(name + "." + method + " returns " + e.getMessage());
1 C8 b3 |' u# c" o7 O T System.err.println("The process will be terminated.");
/ i; b8 m9 b7 a1 p4 ]- }3 b System.exit(1);. n. E- U2 d0 Y% j+ }
return null;
1 s! {( x) B3 g" { }
' Z, Q3 O/ e f' h3 d1 Y return sel;
: ^9 _/ y1 [! c2 f' ?. W }" F3 `6 u& v( ^8 I$ M3 ~! d: |
8 h) s- `. H0 |' ~$ G7 k
public static Selector getSelector(Object obj, String method) {
* l7 t& J0 j, T Selector sel;
6 c2 G# x% X* t, x) M( U' Z9 T try {- o/ }# H$ n. w+ d J
sel = new Selector(obj.getClass(), method, false);
# m' `' e+ f$ c7 }) ? b4 d } catch (Exception e) {
: j T5 m1 b3 a( u: Y$ d System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! l+ R& b/ C3 Z
+ (obj.getClass()).getName() + ".");
* r2 B B5 `3 a: Y! \ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 h4 J7 s1 V; f+ G$ W( y y, s6 B2 h
System.err.println("The process will be terminated.");( ~# [7 Z/ a; T, P% ^+ G! K
System.exit(1);
0 e; f# Z/ a% `/ H! ` y3 k" M7 G* A return null;
. A: O" ~% F X }( u% G2 G( Y; \9 U# B
return sel;# T7 y `2 H; F
}+ Y+ ^6 |1 C6 X2 @
} |