import swarm.Selector;
. D: h; [4 e6 z- q( w& X0 L
! k1 I: J- E1 b* p) E/ Xpublic class SwarmUtils {, o# R) R; I6 R4 T
public static Selector getSelector(String name, String method) {8 Q1 |. Z* y# [6 [6 Y/ u8 u& O, h7 x
Selector sel;
3 W( ^9 r/ L6 R+ ~3 V/ ? try {
5 N9 ]7 ]. I. }; ~* i: y+ L5 M! { sel = new Selector(Class.forName(name), method, false);0 E& l" P0 E% X8 E: L# ^6 P$ o
} catch (Exception e) {
: c& V4 r/ t* D# l7 h System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 D/ `8 [6 u: q3 F0 b System.err.println(name + "." + method + " returns " + e.getMessage());
6 f8 L" R! [ T5 x3 [( d System.err.println("The process will be terminated.");
( c4 _ b! b! g9 N. M S0 B1 U6 e System.exit(1);
* q; N6 g0 \5 t+ o return null;
1 S' b0 O+ }2 d I$ i) D }
& T; @1 R* l* q1 e; T return sel;
0 A5 j6 s+ o& T; m9 K }7 \" t* X. O# M# j6 G, g
! I" P( o- m" x g, ] public static Selector getSelector(Object obj, String method) {
% N% E; ?3 _) M H Selector sel;* q c# L! W. c9 m; U5 {
try {! _" c. { ^1 z
sel = new Selector(obj.getClass(), method, false);
' w/ O+ y9 R7 e' Y7 j- Y } catch (Exception e) {
+ k {5 u7 z4 \6 U! \, k4 Q' y% J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) |. m3 }6 `. g( b8 C9 s; J + (obj.getClass()).getName() + ".");. |" T' S7 r* x& H$ l4 z) n- G$ W
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: ]/ q* n7 |1 b: s+ ~" x7 y; I5 Z
System.err.println("The process will be terminated."); Y/ v$ v; i2 p4 L; Q$ ~
System.exit(1);
4 C0 K4 ~ I$ I6 ^* W return null;
5 e3 m7 o3 ~" A8 s }% o; ~+ v. r9 }
return sel;5 ?6 s& N: Z& V) f0 h- G. X
}
) h5 v M/ L1 h4 U; [* A/ A9 F} |