import swarm.Selector;* N$ t' a, [- ]
V. E2 C) b- h# g& G& S. wpublic class SwarmUtils {6 n" c9 z; I/ V L3 T7 ^
public static Selector getSelector(String name, String method) {. M9 D& N3 P- z2 `. g
Selector sel;( B2 B5 K+ C# f, x/ _2 B& @
try {
6 k8 K/ h: d# L& s, O sel = new Selector(Class.forName(name), method, false);
+ f% y- F, @( S- o; Y2 E% L } catch (Exception e) {
! u1 ?# H/ b, R/ k) G: u5 s: B0 ]" e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: Z2 ?! q8 H9 M8 D; F
System.err.println(name + "." + method + " returns " + e.getMessage());
) o3 F7 a: q4 W S& y System.err.println("The process will be terminated.");
1 C7 w& G9 y/ X& K( w8 ] System.exit(1);+ n5 o' ~! m" U) m. h2 E: r, ^
return null;+ g( q3 g0 @/ P4 j6 g7 X
}# m0 O: n+ g: h& V2 W; s# q
return sel;
7 e) ]3 L2 x. z/ O/ W) d }
7 |! t, I4 Y. t* c+ X1 c4 y3 B
5 | C5 J3 B: _% S0 t! r public static Selector getSelector(Object obj, String method) {
5 D+ H [1 m$ b M; R: F: v Selector sel;
! L& m( \" y) G: ?$ {4 _ try {6 x6 T: I! I" I# b1 M8 I
sel = new Selector(obj.getClass(), method, false);1 k2 {5 R6 [+ n2 l/ a& e3 v ]
} catch (Exception e) {
7 y; g: ]1 z' w4 b: C" d3 g System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "1 l& F+ R1 U6 G$ M! f* v- ]
+ (obj.getClass()).getName() + ".");
6 d0 X+ H" z1 ^/ G* P System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 ?( P' _* m+ }( X3 j System.err.println("The process will be terminated.");! K \$ c$ o: g5 C& a, C3 `) o
System.exit(1);
. ~) Z! B# A2 h3 n/ M& ^ return null;/ j' P) Q1 }. |9 l" ?( v
}
1 i1 ?% t; f6 P$ l return sel;7 Z. v/ F9 ]# Y, |/ [
}5 Q0 }5 v# M( F3 {+ h' @
} |