import swarm.Selector;6 e" h7 D; ]* K
4 }4 ]: K* c% Jpublic class SwarmUtils {' D; ~9 v) J! I. o' {4 A
public static Selector getSelector(String name, String method) {
4 u& P b, C1 `, w2 s3 d7 r Selector sel;' o4 Q: H5 n3 N7 O) y, F3 h+ T
try {
1 d3 U3 ~0 b* x8 b6 H1 a sel = new Selector(Class.forName(name), method, false);* w& b3 @2 s2 a G. J
} catch (Exception e) {
& |6 S' I1 }) |4 s$ B System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& T1 W; b& k' c" `+ M9 z8 p
System.err.println(name + "." + method + " returns " + e.getMessage()); e }2 v( E8 R) ]3 t N4 r
System.err.println("The process will be terminated.");8 s3 b( m0 O3 `+ T2 G& h# `( z
System.exit(1);
: N& g% l% r& g, x ]* U" |( Y return null;
5 g6 W8 Z1 O% \) Q- p; ~1 x }! k) h3 L2 P# G
return sel;1 l8 j4 R+ l V% ]/ t
}
% C. t( V! O% a% x! u$ w/ {8 R; C! J( P: `+ M2 g% r
public static Selector getSelector(Object obj, String method) {
|1 l" B9 X( _9 c8 }5 U. m! L. {5 l Selector sel;, z$ k, y; \2 q; Q7 c+ P
try {
& V& ?) z' S' I" O sel = new Selector(obj.getClass(), method, false);" P( O" W1 N! m4 b
} catch (Exception e) {* }9 o, [7 m- Q% J; ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& F. a5 `' q# H7 U; I
+ (obj.getClass()).getName() + ".");
1 E8 z1 s5 H( H2 s1 {) S( v& [ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. E; D7 v, t+ {9 h/ U/ D% b
System.err.println("The process will be terminated.");0 T; r, }8 k$ y7 t$ ~) B
System.exit(1);5 N& ~4 ^, N; b3 ~) {' v: G
return null;+ x% |( `% u4 d0 _- ~- q
}
& N& `7 G7 Q. w1 |* D6 [ return sel;: t9 o$ D; j( x9 k, |3 @
}- Z5 v5 r4 v5 T! K4 U7 ~
} |