import swarm.Selector;& i7 B9 O3 y. [6 X2 R6 l
# g2 ?/ A- n6 B/ T! P; xpublic class SwarmUtils {4 Q& H s: [% i. r' [! r
public static Selector getSelector(String name, String method) {- W1 q" b6 | h; w9 T1 f0 [
Selector sel;# a/ j: |2 d$ S9 I# d3 h! u6 E9 `0 v5 B
try {
) {1 e6 w1 @# ~3 Y3 w sel = new Selector(Class.forName(name), method, false);& a+ o. ?2 U2 i( `" q( l! Q# a
} catch (Exception e) {- q! R ^# R& o( N8 L
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: y6 E: m2 ^; E+ o
System.err.println(name + "." + method + " returns " + e.getMessage());7 O& }6 k* o2 B9 `& T3 _; b* s: H2 a
System.err.println("The process will be terminated.");
* `. Y" f+ u& e3 m System.exit(1);* z$ F' q: [8 M$ h& U
return null;" v' v- o o7 R8 D* N i, l8 b T: L
}9 A7 n' c, P# i2 w/ S- m( X
return sel;
* D' b( C! W' Z }. V% a3 |$ _& a5 {3 S
/ u4 o. v4 v6 r0 y public static Selector getSelector(Object obj, String method) {
3 O7 e) s2 M* ~ [ Selector sel;
8 V! N" Z3 h" _, }6 \1 \2 @ try { I1 H! x T& }5 g# {- {- R
sel = new Selector(obj.getClass(), method, false);
0 D+ m- e0 {# N9 V* b3 D: k } catch (Exception e) {! D6 Z, C/ Z: { r1 i+ D
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") p: v! ~$ Y: |0 B, f7 ^) i% ]
+ (obj.getClass()).getName() + ".");) u" c* P9 r; A {
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
3 T+ Z# t7 E) [$ ^- b$ I- ^ System.err.println("The process will be terminated.");! S1 a' j$ X2 \4 b
System.exit(1);
* M) Y; A* L# h return null;$ o; a @5 C0 o' N. {
}: L; p5 [0 U ~+ B
return sel;, c$ d6 ^# t' E+ c; z+ T
}
4 {' D/ p% s. B4 W/ x} |