import swarm.Selector;
0 X4 l' p! U$ ]6 U
# V' t6 r {, U; _4 ]' F* a" [/ Bpublic class SwarmUtils {9 ?6 e4 {2 G3 f' C. q
public static Selector getSelector(String name, String method) {8 T( T# e3 P; y+ b: q
Selector sel;
4 U+ g+ ~' c5 i m/ P) S N try {
( f5 ^2 T+ Z& M' K) S$ b3 h sel = new Selector(Class.forName(name), method, false);3 A$ I) K) G1 ~) I2 U
} catch (Exception e) {2 U- j2 Q8 `1 J$ O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" D: n4 A! ?9 s7 G System.err.println(name + "." + method + " returns " + e.getMessage());& `6 X; q7 b( w4 s$ N* n: z& y0 J
System.err.println("The process will be terminated.");. Y) J: c; @3 {, a2 R- B) i
System.exit(1);$ u- n5 H6 i) b3 [. I2 a
return null;# d8 |$ T2 g- |, V
}
) P# n. T4 F% a! h, @ return sel;
) H2 W- V1 z/ ^1 `/ k }
7 B2 @2 f3 S$ h/ T' j2 \7 E( R; G S7 C. m8 p$ S. e& C
public static Selector getSelector(Object obj, String method) {
7 k, h- r# Y+ S% {' s: |6 p Selector sel;* y4 m+ D! z8 U+ E5 c' I, l
try {; P% _1 M9 r! l- A% b
sel = new Selector(obj.getClass(), method, false);
5 E+ G+ j! U. M; s8 M3 v } catch (Exception e) {$ Y+ Q, C, I2 b
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 }! ?# e6 x. { + (obj.getClass()).getName() + ".");
9 e( i9 ?8 j8 o# n3 q0 C7 O/ a System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 f0 l: K1 u" ?( b" w
System.err.println("The process will be terminated.");
2 _4 K U6 z) }) @+ w n System.exit(1);
& P+ B% ^. h8 B z2 S1 O* J return null;
7 w0 Z* q! F$ Y& R7 m }6 v4 E; R8 k5 u5 k
return sel;- r: P" O0 k6 _( z
}' S0 P9 d. j. W% b8 ?, B5 u2 L/ ]
} |