import swarm.Selector;/ A+ C6 {* J1 D
; Y9 ~4 l0 Z/ T) r v1 u
public class SwarmUtils {
7 X) m- a# v* ]9 a* o+ y9 X- Y public static Selector getSelector(String name, String method) {$ J, U5 i1 L5 Z, X: x9 M2 ?
Selector sel;2 c6 |0 Y: Q# D* c
try {
$ W6 P: ^2 w! x; d( b8 ^ sel = new Selector(Class.forName(name), method, false);6 t. X0 Y$ s3 H0 f S8 n* t7 O
} catch (Exception e) {) h l, m3 A. f2 h# u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 e- @' X! \! X% c
System.err.println(name + "." + method + " returns " + e.getMessage());4 P6 s, _ i2 D8 z. j( \- h
System.err.println("The process will be terminated.");
( U% \$ l0 M! J) J1 \ System.exit(1);
; [7 K* L" l4 N: q return null;: e( {& h1 y# Z& _' \/ ?* k
}
* H# e2 R( K. {1 H$ x$ s return sel;
0 n* w2 V6 [+ B$ {3 O' p1 F; k }5 [6 E! s3 t/ S8 _0 O2 @
' C3 B H3 S( s3 d8 ^: i* V1 {
public static Selector getSelector(Object obj, String method) {% ?8 b; j/ D9 S" q) |! w5 H& f
Selector sel;+ V$ l) D7 V" p1 `' Z9 d
try {
/ q$ _5 K T. a- g+ C" ^ sel = new Selector(obj.getClass(), method, false);
2 `. Y! V8 q# W4 c: B% {: g! ]. O } catch (Exception e) {! R% O' \& m6 W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& ^/ H0 W2 Q: x, ?5 V% W + (obj.getClass()).getName() + ".");
. b$ X# [3 f& I$ X System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' U0 u) w: S5 n2 }9 _
System.err.println("The process will be terminated.");/ R. w$ m4 M7 z2 r
System.exit(1);
: t; `; _3 Y( |" r return null;; ^0 ?8 c" m/ S' k M% K2 l% w
}
6 G% G0 h2 L% Z# U' T" ]4 p4 P return sel;
% y, Q( p( K- Z* I6 c' R }
1 C1 A' e1 ]9 X% G} |