import swarm.Selector;; T# I B6 A; a$ ~: o
) ^- G$ a+ n) G3 ]public class SwarmUtils {
3 c2 A% S* M" S9 I: D public static Selector getSelector(String name, String method) {: x& s# z# Z/ p/ w7 l L
Selector sel;
) K8 E2 k% i3 o* q# n0 ` try {
* T' i! K. E" M! r( v, ~ sel = new Selector(Class.forName(name), method, false);
; d* j* y6 D( }: D } catch (Exception e) {$ w* q6 ^5 b" z: _. H# C" a
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& ?4 @6 v( \# v, e4 O% o! c
System.err.println(name + "." + method + " returns " + e.getMessage());
% ]1 d* ]" v9 `3 f8 Y/ a System.err.println("The process will be terminated.");
6 I0 E A, X: C6 m9 ~1 z2 c System.exit(1);
' p* t, V1 ?3 Y return null;
$ m# N9 q0 u8 W8 p6 D/ A: P* Q( j# d }
" X6 ~* U: j% a3 J6 y& e& H" ` return sel;8 \# L- ?' n; a: N
}
8 [. H6 J/ K8 M1 a7 Y7 n6 [' Z
+ t& C3 o5 L m! ?7 P public static Selector getSelector(Object obj, String method) {
! k& |' h1 |: z- H" B7 |" R Selector sel;4 `7 y- h* y* ?
try {( j( L2 ^: s @7 s6 _- }
sel = new Selector(obj.getClass(), method, false);
+ j$ Q- ]: h4 \+ y) U } catch (Exception e) {
6 D' D2 i' w- N6 y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# Q5 G$ x4 S* X" V) X& j! q + (obj.getClass()).getName() + ".");
8 }) q8 a& d @+ e* U% ]- L# M System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- f7 B$ u- t( Z. d3 R* H4 R System.err.println("The process will be terminated.");
% d' c. R* n6 C2 x7 ]- r System.exit(1);& n8 W. H! {3 Q
return null;
1 {. o* U/ i9 r }
- \1 l4 R. z2 ^4 S$ S5 Y+ j return sel;$ H6 x# \0 K8 x) y" S9 `4 Y( L/ L' T; W
} H: b( W# K( O- j
} |