import swarm.Selector;
b( U9 S) u( y9 E! m/ \. B
3 l8 i# k9 j9 V J- V: C& gpublic class SwarmUtils {
4 _$ K, B- p* g [' l2 x$ {' @ public static Selector getSelector(String name, String method) {# F& T+ V0 d _; x3 |8 D4 N9 q" u
Selector sel;- W5 K$ s9 |5 m% e
try {
n8 _; O d, e! @* j sel = new Selector(Class.forName(name), method, false);
% E K; ^# E. R. X% ]" x. N9 P } catch (Exception e) {
$ b4 u y3 g! B System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: B/ z0 t5 y, W( U$ J System.err.println(name + "." + method + " returns " + e.getMessage());
% H2 U$ A* I1 ~1 c System.err.println("The process will be terminated.");
, m/ V1 w. j! m2 f( P$ b System.exit(1);
3 O( `5 b7 R5 j& d4 X return null;6 G# f; {( K& w/ ^$ z
}0 p) ^8 R% i6 M& ]% g5 x9 ]
return sel;8 P$ ^4 a$ ^+ E4 G. \# A
}5 |, F y$ N* |3 j8 N$ ~
5 q4 p# j' y6 z, @1 A) U( w, ] public static Selector getSelector(Object obj, String method) {9 V& k6 i7 O- u$ T. W
Selector sel;
" A' k3 u5 a" i/ i try {
8 y' |, A' Y6 j: e sel = new Selector(obj.getClass(), method, false);
0 L0 p1 O ~( K$ k } catch (Exception e) {
9 n% @5 i. e4 \! P3 h" H System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# {& Y& w! A @' X* h + (obj.getClass()).getName() + ".");1 d y3 H# C6 b, b% r
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) f! c9 S7 U# Y System.err.println("The process will be terminated.");
1 t6 r( j( ~8 r6 y System.exit(1);- J3 T3 _& d" j# N
return null;0 d2 U( ~$ V( n* f
}( P; i# T2 H) _/ w2 r9 X
return sel;
8 \ P5 x% `" m d% m& ?2 ~ }) ^+ \0 T* ]7 d5 T2 G% `
} |