import swarm.Selector;2 H0 B" ]1 |' W. Q& f7 r* d
5 u% ^* d5 g$ I& y) Q
public class SwarmUtils {
6 x! U' G+ T0 W. } b8 z0 f$ P7 i public static Selector getSelector(String name, String method) {
8 U0 e( s- J) A; S# c5 ^8 k2 x Selector sel;
4 s6 F7 y0 F* ?+ T try {6 d2 d3 b: \ P$ X& y; z* e6 z
sel = new Selector(Class.forName(name), method, false);. n5 A% ^* h5 j7 v! N8 u6 B. l- j6 O! E
} catch (Exception e) {6 Q: O1 T( _4 T. t! `4 o7 w" W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 e3 p( Y% `9 T/ [. J1 `
System.err.println(name + "." + method + " returns " + e.getMessage());
3 S% ~& V1 Q' I7 F System.err.println("The process will be terminated.");2 o) f2 A# i$ b* L+ l0 f" @
System.exit(1);+ x4 J9 a" ?! [: i: q
return null;
9 p5 q% w8 }9 Q7 N. C }
% C* \8 ?* S0 I% N return sel;
/ b$ x1 W2 N# P9 V# X+ b }
% w5 L% J1 H. [& p$ W. Z. ?& d; o8 Q3 B
public static Selector getSelector(Object obj, String method) {
8 n$ Y9 ^, z* p5 t Selector sel;! u$ ^/ H% C! Q* G6 j5 }. m1 Z
try {6 {, @' s8 R) w' |; g6 b
sel = new Selector(obj.getClass(), method, false);
, h& k1 n- `* T% K( ` } catch (Exception e) {; M/ O# D4 | Q$ j. T+ w
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 l q3 a3 R3 F9 G- Q + (obj.getClass()).getName() + ".");6 U/ o: h, U! V4 h; k9 A
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
^. T" t& \, d9 [! _) \ System.err.println("The process will be terminated.");
6 h% u {. B" u0 q5 I! C* x; ~ System.exit(1);
% O4 y# I5 G9 @ return null;$ N1 K6 @" l/ x* R- I- V
}6 a; Q3 w& M( K& b
return sel;
7 C7 C; j0 H5 Q. V0 O& s }
2 R: Q! Z) k# P7 b* U! i} |