import swarm.Selector;( u# j B/ a$ n4 w' t
, x" I9 s* }# t v" K
public class SwarmUtils {
$ q/ c7 h& W+ u4 ]1 d public static Selector getSelector(String name, String method) {
- z h1 ~9 B# x8 ~ Selector sel;. A3 X( a& i# z4 V/ v: w
try {* e1 R+ C) ~0 X
sel = new Selector(Class.forName(name), method, false);3 a2 c+ d% u4 t1 C
} catch (Exception e) {" K# J- T6 }" u c) h
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! @5 E+ I2 z3 u4 O" f8 s* M* x5 w System.err.println(name + "." + method + " returns " + e.getMessage());
8 k; h/ i8 A! \+ i3 I5 s System.err.println("The process will be terminated.");
! k. ~% i" E3 I e4 E' y System.exit(1);
- s/ r. Z* T4 f5 d3 ?! y' H# K return null;
6 K- h u2 z+ R! { }
- h; q# V; c$ g, A0 c5 x return sel;
7 F9 p N/ y' z/ i% N' I! `) N }
+ B3 A4 {# e. _' u9 D+ T. x3 F( S
; d- m$ [' @5 ?2 q public static Selector getSelector(Object obj, String method) {# w6 z- x5 ~% D% e# T" b. ^
Selector sel;
! Y! i5 u+ }8 S+ }% y try {6 V: x& v$ d/ j
sel = new Selector(obj.getClass(), method, false);
. [2 ]+ d( N/ B } catch (Exception e) {0 k$ f* J8 \7 [2 T0 I' f9 x
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# M. N7 z0 ~3 n* G2 w5 s! [( L
+ (obj.getClass()).getName() + ".");
& _4 R# e8 R5 T System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 U8 p; O: `6 `6 ?1 I) X% t System.err.println("The process will be terminated.");$ r' h* P4 R5 K+ u
System.exit(1);* p) l' g' N3 w5 ]
return null;
: E% z2 @& Q s; m* k0 I }
$ d) e& m l3 ]9 R* d: f1 d return sel;4 B" e/ V/ M' [2 h# `, j
}5 H |- `4 a3 Q, S6 r% Z
} |