import swarm.Selector;
% C9 r6 A) x% H( O( D9 V7 e& H1 {5 A) N& I2 w
public class SwarmUtils {/ E; X% m/ O+ G
public static Selector getSelector(String name, String method) {3 @- N) k7 g' P; m: R
Selector sel;+ r5 V J |* V7 M/ B' }1 w
try {: J u y" W$ m9 [- P9 z& ]8 e4 B% ~
sel = new Selector(Class.forName(name), method, false);
! F/ w8 W& W4 Y; Y8 X } catch (Exception e) {
& m1 l0 w n T" w" g7 ?( A2 Q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
0 f$ {, f6 F& g7 S System.err.println(name + "." + method + " returns " + e.getMessage());
1 `/ M0 r: P- F* F8 `4 V System.err.println("The process will be terminated.");9 R4 |5 c3 ~( w e6 V+ s$ o$ e
System.exit(1);& v: n& {. ?9 r' ]! C7 ]
return null;
# b* ]8 }6 M, |& k% M0 T' G' |% R }
( V& p8 X# K# d return sel;
9 N0 B0 s% V- c# o( P/ t* e }
( v) o: A* g1 T' o0 ]8 y
6 Y- Q6 a) n- H6 S* j4 m public static Selector getSelector(Object obj, String method) {& C5 v& y" L: Q6 w
Selector sel;* I- B* s2 U8 d) O$ H0 U& s+ M2 F
try {, s, d2 X2 n0 U/ L5 o/ l; V
sel = new Selector(obj.getClass(), method, false);$ }) d' J/ O8 C, W& @: Y: G
} catch (Exception e) {( ^5 r9 }9 @. w3 t3 I" U
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% Q% \; K! X& G1 m1 e" O: a! P
+ (obj.getClass()).getName() + ".");% e% v0 v0 X7 |$ @% z* b" U
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, Z& f' l3 B$ C n/ ` System.err.println("The process will be terminated.");
& @3 D* w/ ?9 g5 P3 G System.exit(1);
) T2 Z0 F9 {# v& N) Y return null;
1 b* `, `# N# r. p4 u( R' ~/ r }. t- T- L9 K0 D
return sel;7 R2 e" J+ W$ i( Z- L. ~+ F8 [( S
}7 I3 E N, g6 u8 c ~, t
} |