import swarm.Selector;( |# v2 f, @$ r" W0 c
+ I7 x9 [7 R4 N. J( ipublic class SwarmUtils {6 p" o0 T& M0 \7 j
public static Selector getSelector(String name, String method) {" @! g0 _% f/ s p" c
Selector sel;
9 Q M- k, h m, {% ?4 ^# E try {
4 v5 e& {, u& ?& A sel = new Selector(Class.forName(name), method, false);. k- I3 m* k6 k3 C' k4 P1 K' Z
} catch (Exception e) {3 j$ D% k: a8 p' o
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");, F5 n5 ]5 d/ t& f3 ]( A; v4 f9 O6 P2 p
System.err.println(name + "." + method + " returns " + e.getMessage());
& x5 v, S5 i+ _( u: @ System.err.println("The process will be terminated.");4 x5 B% ]2 s. k6 R
System.exit(1);; `8 u* k4 _- _7 X
return null;6 K/ o( m$ V2 I! Z* l4 N9 \
}0 I2 a8 Z" K# t( \" l4 Q
return sel;
" h, A* L' T+ [9 c) V4 L! K }
( a1 I6 a% \# [9 K! B" r: j6 y5 i' B/ O7 m/ @$ {
public static Selector getSelector(Object obj, String method) {: _1 V/ i/ n6 P! z' f$ D t
Selector sel;
: A: t! L( j& ^5 s+ E try {* A+ G( l% a7 w @( J# O0 s) Y2 G
sel = new Selector(obj.getClass(), method, false);
+ k0 m0 f3 {6 Z4 D' V1 P% B } catch (Exception e) {
9 e/ N6 e3 k* M7 h5 j9 k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 n0 m; C* u5 U + (obj.getClass()).getName() + ".");
. T; D) A" B! f# i! F System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());& T5 i' [: `* s' I) R9 D
System.err.println("The process will be terminated.");5 O2 H G0 M: M! E2 N$ e$ H( K5 X
System.exit(1);
/ v$ I) H+ T! C3 D5 s1 P return null;
3 D5 @; F w9 c( p9 l: n }6 M* O4 r$ {" g8 C8 p8 V
return sel;3 H( z, e6 P& _9 M
}) V& o2 x3 K7 W: x- g& }
} |