import swarm.Selector;
$ A' d4 p$ n( L9 l u* L2 Z6 ?" } o9 T1 E1 R
public class SwarmUtils {, d( e, m' e# s9 B* D# g$ [
public static Selector getSelector(String name, String method) {, Y+ [" N* s% Z5 I/ n+ U& W4 m# ?
Selector sel;
: k6 d# I: \1 y* h try {
6 X) T2 z K* i& Y0 a5 Q/ V5 ^) k sel = new Selector(Class.forName(name), method, false);
$ ]0 t- V: N- O: a- [ } catch (Exception e) {! q7 N$ T/ `& U, _
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; L9 g' p" n* i( P5 `$ P System.err.println(name + "." + method + " returns " + e.getMessage());
$ ~/ C; o8 j' E4 s System.err.println("The process will be terminated.");
: _8 N) ~- J) F System.exit(1);0 k w; W: {$ e" O9 W% c
return null;9 D {* _. r/ i Y( O. h
}
1 I- Q. {2 B! G% @5 t0 O, h7 p% o) y- }5 F return sel;! l% |7 f& P* _+ G
}
2 H3 T( u% ?2 _1 R
3 A: k9 \) S- @% P* K$ H2 |5 ^" m public static Selector getSelector(Object obj, String method) {
( ]! b. z7 U# t) l6 O- W* f Selector sel;
6 J% C# s3 t4 H* U9 p( B# x- ] try {# L$ h; S/ r0 G" u
sel = new Selector(obj.getClass(), method, false);3 y' F- M- [! g) I* c& _+ P
} catch (Exception e) {. z6 u4 K: m8 z# x$ ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", X& D* N! N* u1 v" Z1 t# T
+ (obj.getClass()).getName() + ".");9 J6 W- }, E* O' ~, u0 F% |
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 ~" H0 R& M8 s8 z3 P System.err.println("The process will be terminated.");2 i- g) @' m8 g& x" |* K, M0 o5 K+ w
System.exit(1);
' M9 F! K4 N( C8 `( K$ u, R return null;
) @) v# n( N) j5 d* N }
/ p0 Y3 R- {0 z* M return sel;
$ A& ]2 x! U8 H' u# o" V1 O }2 P- W4 h7 X1 K, s- B* X, C( {0 D
} |