import swarm.Selector;
% y: `& m9 B$ |# w$ T6 B5 [6 z5 f1 O( w' E8 t
public class SwarmUtils {& o6 r# E* h$ x/ A8 ~, i
public static Selector getSelector(String name, String method) {$ L; N% i1 h- s4 U, A: H
Selector sel;
. Q' t5 }, o7 H/ p" a* w8 ^ try {' n* n E+ Z! K$ q8 O9 s2 n- w. |
sel = new Selector(Class.forName(name), method, false);
$ U# @3 `0 P8 _1 i* `+ m3 Y9 N: u } catch (Exception e) {! D2 S* c5 r1 C2 w1 n8 G
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");, y& {+ c. o; I* d5 z
System.err.println(name + "." + method + " returns " + e.getMessage());
" A+ b: _, v: _ System.err.println("The process will be terminated.");+ V: j( y: d( X6 j6 j$ J
System.exit(1);4 W5 o0 }: P: Q; @4 b2 f3 _8 p
return null;
$ R! {- G/ W- T$ [3 q: E }$ ~: W D, q# t6 u8 J" f. g; G
return sel;# D' F1 c. ?7 }: I
}
! x$ G& n. _0 |6 P. P- ^4 C9 |- y$ C7 {! J
public static Selector getSelector(Object obj, String method) {2 N5 N: X( t8 D8 o
Selector sel;0 j4 y1 A7 u7 |; K
try {
1 `$ T- q) t" o( Z$ T sel = new Selector(obj.getClass(), method, false);
' U/ b- f1 V: Z9 K, Z9 ^2 e: Y } catch (Exception e) {
7 g9 w" L! j, V+ {8 v/ [5 M System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 T m7 g# U& {7 N- V' D# P + (obj.getClass()).getName() + ".");+ @8 x' Z y" M8 v5 H4 J" p
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 T) V5 S. t8 m8 Q. F& T2 i5 ~
System.err.println("The process will be terminated.");7 [, I1 S$ N% |3 J% {. u" R% a
System.exit(1);
* d1 W/ F$ q4 b! @/ @ return null;
/ h- S8 Y- |$ \! D' u }
6 Z/ T! W$ T( a( b6 E return sel;% w! w% |7 h) k* S; x+ B
}
. Q8 t3 W: r, z} |