import swarm.Selector;
1 o5 f: a- J7 }, ?' t
4 P& F. E2 y6 @" gpublic class SwarmUtils {; y. C1 c, @% l. r3 K( w# ?) S0 e
public static Selector getSelector(String name, String method) {
8 i: g- o: U( L, P) r! i Selector sel;
' S, a3 ^5 t* o( `9 Q4 _ try {+ |8 Z+ c }$ c( R' ]
sel = new Selector(Class.forName(name), method, false);
: @/ a: M0 S1 c: a- k3 r } catch (Exception e) {8 ]% s2 W3 h$ h4 g( f! o8 g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
+ z! S" w$ y5 R System.err.println(name + "." + method + " returns " + e.getMessage());
% e3 g2 A" Q$ D# y2 s9 Z. _. M. Q System.err.println("The process will be terminated."); z8 b: T0 p0 a1 Q
System.exit(1);
6 p) T3 {# h8 F3 P' Q L2 g return null;9 R/ J2 B, y3 _" ^! h7 X. p
}
: z7 @4 p& a6 y% S& K$ R return sel;
( b: k1 S2 [! Z6 K0 Y1 z# V }+ Y: p- ~: W6 |: z! N( n
4 B3 G- F0 A0 Z0 }6 n public static Selector getSelector(Object obj, String method) {/ m- R; x) N, Z( G, m; P
Selector sel;! Q$ ^. ^6 d M& G4 P3 }* F4 Y
try {
, e8 `5 d- o( P5 w. d" g2 L sel = new Selector(obj.getClass(), method, false);
( e7 G$ p; v# Q& k } catch (Exception e) {; |/ T& h, u- _6 t7 t. l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) Z. v7 q; f9 p + (obj.getClass()).getName() + ".");3 c0 z3 {4 z3 o m7 J. s+ @
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 N; j) E! q" n/ j$ E, i( H8 m System.err.println("The process will be terminated.");* f7 ^2 q& p) Z+ M
System.exit(1);
0 \: l9 Z2 N/ w4 ^ return null;
' S& b: }# R- H6 n- U }, W* \8 A3 ?: i: m+ l
return sel;& E+ H; ^6 @, _' L+ Y7 N3 [) }
}2 I- R/ l% W4 q7 k2 L. a% E( u
} |