import swarm.Selector;% ~* W, h7 z) C e+ ?5 o! L+ y
2 M" C: b0 f s* H6 f- [
public class SwarmUtils {' y4 S, r* W: ?1 ^) H' ?
public static Selector getSelector(String name, String method) {! ]+ r; h! s2 o! S
Selector sel;
( T; q# |1 F# A try {/ n$ a4 O4 h. w$ V s9 D8 R
sel = new Selector(Class.forName(name), method, false);
, J6 x, C2 @- r# h4 X5 d } catch (Exception e) {' p% f( B, \2 @
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ \: ^3 ^- k# k7 z% I) } System.err.println(name + "." + method + " returns " + e.getMessage());
! H& o7 {0 A2 i/ n1 m. M* L" Y System.err.println("The process will be terminated.");
1 |) D' ~ c$ h6 g2 y, b- t System.exit(1);. x2 W7 c- u' p; m$ C( c% E) x3 _
return null;
) Z$ }: ]0 E+ O }
" q+ i& k q5 Q5 I# M8 [ return sel;
0 Q) t. K6 R" m& N& y }; a7 j* k. E8 r2 v3 e7 S8 j
, }- o! V8 M s5 D
public static Selector getSelector(Object obj, String method) {
- k Z6 n/ D( I7 q1 ~) b2 g( Y# Q Selector sel;+ K% [) k) M# U0 P7 q
try {2 y9 U5 K a2 e
sel = new Selector(obj.getClass(), method, false);
9 [+ X! [7 b: d" t$ ~6 U g2 c } catch (Exception e) {7 A! c5 m! p, `* h1 B' M6 G/ P
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" `( _- x& d, U: Q' Z
+ (obj.getClass()).getName() + ".");* m+ i! o; y$ q, b0 u" o8 C
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; q+ e' ^$ l* G
System.err.println("The process will be terminated.");
7 ]3 _# d) v2 _# z' n System.exit(1); e+ x8 K/ `8 H+ L% p% r, }
return null;$ ^+ i) m3 {1 s' U
}/ U- D/ D2 N2 r/ n1 a/ X I a
return sel;
% d; i6 d* t, B) U }! y2 u( W, F# E' B+ e9 R! i4 ? ]* _
} |