import swarm.Selector;
% Y1 P7 n. ^5 r" C# Z( o2 m; g
' W3 [/ r7 v5 U, d" ~$ ypublic class SwarmUtils {: u9 M" y' W5 e- o6 W& g
public static Selector getSelector(String name, String method) {; M" l4 Q" `( P: s, y: m4 d: `, }0 m5 \
Selector sel;
: O: X% p. v8 e( w" b8 X8 q- m E! n try {
: V& D9 W5 J) b% D$ z, x9 E+ d sel = new Selector(Class.forName(name), method, false);
1 Z( P9 x* G# \7 N3 Q7 m0 F } catch (Exception e) {
# e m8 V" r( c1 N System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
3 u- T# p& L/ Z0 S0 a1 d System.err.println(name + "." + method + " returns " + e.getMessage());7 V7 |* O9 w, S
System.err.println("The process will be terminated.");
) Z, Q& Q( @2 ?" ^9 t4 v System.exit(1);$ o& @4 ^3 F' i; L. Q
return null;
4 B# X) j3 ^9 ^' s/ J* O! Y }
! U8 P; f8 Q7 J7 P return sel;
( R) Y, N" _; e% a% ~' b }
$ Y' E# J- ?: z6 B* F
$ G+ f1 R$ ]" _5 j$ p public static Selector getSelector(Object obj, String method) {
- M, B7 l! l! S9 }( R- F T Selector sel;$ x4 Z6 }7 N( d
try {
$ u9 V5 m7 O. S, ~ sel = new Selector(obj.getClass(), method, false);
5 K/ W0 c! J2 O: @ } catch (Exception e) { U, F9 ?. U& ]/ J9 v2 O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "6 o6 P7 ]4 T Q0 m, ^
+ (obj.getClass()).getName() + ".");5 s9 ^/ }/ M2 z6 m' y! j5 Q2 A
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 ~7 v4 O0 w, a" |" O: S! Y% L
System.err.println("The process will be terminated.");- S7 F6 Z2 f( N1 K3 R3 o
System.exit(1);2 m( k5 A8 L) S/ z: Y# F3 p
return null;9 ~" o7 ]' ], I1 L" j
}
" v* Y$ a. u' D( L' L7 K return sel;% j/ c6 g/ ~! `+ k. u8 S0 G5 V
}
2 A" V: n3 y$ z7 P! {} |