import swarm.Selector;
! _1 |8 ~& f5 q) s/ \. t
3 \% I% h; \2 o. O2 h9 ^4 ?5 [% d0 apublic class SwarmUtils {+ W$ K' T- f A
public static Selector getSelector(String name, String method) {0 _ |* p- [% y9 C# _8 K* X8 z# H
Selector sel;, {9 q" T5 K6 {" k. {+ z
try {$ p0 d! G5 j1 G, |& `9 p5 K
sel = new Selector(Class.forName(name), method, false);
' |/ z+ @8 L( H, ~, v0 w! N } catch (Exception e) {
. v4 ~- y6 [/ x# ^* f( y/ ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* {! l6 d q3 ]) n# A
System.err.println(name + "." + method + " returns " + e.getMessage());
4 R7 w. r, u2 a7 W4 c0 o System.err.println("The process will be terminated.");
% O( |+ O4 @, j h4 C2 | System.exit(1);
" ]3 o- C# l8 [4 F% u+ A. d2 u return null;5 k: j% [) x, R4 F' Q
}" { O- @$ T6 Y* K
return sel;
8 K& Q" o7 a$ o1 f T+ I }
3 q1 F U& b, r4 C9 U5 p
1 w J2 q( ]9 S% F9 B/ g0 c public static Selector getSelector(Object obj, String method) {
U; K6 W- d* y) K, x2 L4 W Selector sel;7 n F5 a4 {: c' `' d% J- E2 B/ D( g
try {
' {$ F' N. J5 f5 N6 X7 Z& S& E sel = new Selector(obj.getClass(), method, false);
; S. X& P; H4 ~! v } catch (Exception e) {: t" n1 }6 w: ]& l) U
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
; T- k7 H# R& } + (obj.getClass()).getName() + ".");- m7 E* c \$ |$ x# K
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 v& N; O7 j) N2 C! U System.err.println("The process will be terminated.");
3 A8 o5 `2 }* J System.exit(1);" c3 q/ ]9 e7 ^% c0 C' D3 A9 U
return null;
2 Q5 C; u) k9 s8 P7 a3 H }
5 ?) y+ t) h% r return sel;
+ D- Z3 g; h* K* w I* K; } q }# U$ i; F& F4 }3 ^+ m, L# D
} |