import swarm.Selector;
+ @0 L- }5 o$ J- Q- n& ^1 S3 H. v$ W; Z( R9 m
public class SwarmUtils {
4 v6 Z; U3 i1 [ public static Selector getSelector(String name, String method) {% q" k2 x. C. R, ~
Selector sel;) H1 u; l8 P0 h2 t0 Y/ s
try {% f; ?; D, J$ c5 [ m" d% D
sel = new Selector(Class.forName(name), method, false);4 {: l- K: S9 [
} catch (Exception e) {
; u/ a; \4 t7 }' A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 I/ {0 d0 B& u/ [2 G System.err.println(name + "." + method + " returns " + e.getMessage());6 x; q* N1 \9 @ }: Y
System.err.println("The process will be terminated."); N2 b" H5 ^- V( ~ g/ G
System.exit(1);
* D2 h/ ^# j: D; Z5 y0 R# Q return null;, p7 ~/ A4 K) U7 ^+ c" g
}- W3 y' {; f! a# d4 r" C' ]5 [
return sel;- A; D0 p% V( [4 P; k
}
2 Y' y5 ?6 T$ K6 G' P" @: _/ M/ n5 r. a, e% c
public static Selector getSelector(Object obj, String method) {
9 N) t+ F4 s* Q6 m1 G6 s$ m Selector sel;
# o, _) k% ], W9 \$ X. a1 l3 P$ o try {" _; z" q0 X: v/ `
sel = new Selector(obj.getClass(), method, false);
5 v' f* F' _. [, ` } catch (Exception e) {
* C( u8 V/ m3 D& W% _ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 \& t+ `9 v( E1 b3 L4 Z + (obj.getClass()).getName() + ".");
$ C6 A+ i8 O) I) T System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# B: j# u: A' O System.err.println("The process will be terminated.");8 C8 ^; m) Y( z: ^" q( Q4 i
System.exit(1);
* \; Y }" U; Q) m0 P5 n1 a- D return null;7 S9 X/ A( L( \! c- _9 Q
}
# g: G5 I# ]- N% \ return sel;
0 t2 ^& w) a' } }
# e# ]& P; r: {7 u& ] S6 x: a} |