import swarm.Selector;
6 n0 ?6 a2 i6 e* X$ {8 T& r; b3 e U- ]! ~9 t# v/ I( B" @! |; z5 y# V
public class SwarmUtils {" k+ ?; g* `- P
public static Selector getSelector(String name, String method) {$ n, ~3 g1 G$ }! ]4 u: ]- ^
Selector sel;
6 S2 k) m, O7 Q try {
. f5 W. ?/ s( _. L& @ sel = new Selector(Class.forName(name), method, false);
$ j$ X7 ?' z C z8 R- u } catch (Exception e) {
o- F7 U* |3 x, X0 Y: s System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 P9 _5 V; }0 g% h System.err.println(name + "." + method + " returns " + e.getMessage());
$ B" K4 k5 H) q, b* c* J System.err.println("The process will be terminated.");: }# M& F E3 y+ J
System.exit(1);8 s- N9 v% q/ R% z1 y2 N
return null;% Q1 t" d& O7 w! Q
}
L' _% {: N9 ]/ i7 Y1 j8 N: O1 A3 ^ return sel;- Z- h2 p" S- F$ F D2 W; c0 e
} h5 m2 u4 D9 F2 e2 Y. R1 R& N
; c, I' F$ E: Z, h public static Selector getSelector(Object obj, String method) {
. h9 y9 O" Z8 D, R0 l8 z Selector sel;
: e! e8 r# ]% X9 {2 S2 C6 [; S try {
2 l% X9 X7 `% j, f3 L* A sel = new Selector(obj.getClass(), method, false);
5 e+ i' T1 b% Y1 _, G } catch (Exception e) {
8 P3 Y7 u: d. C" r System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 e( l' O4 I% p, u + (obj.getClass()).getName() + ".");- D% s m! o$ j7 s/ j
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());+ X: B. g# Z9 C, z# s2 A( A
System.err.println("The process will be terminated.");$ z/ n8 Z4 ]5 a; d# q
System.exit(1);
& m, S0 {! b0 h; r, g4 N return null;- @' o8 G0 P2 y, S
}3 O5 C+ A6 T; n( e
return sel;
6 k j" L# |. O5 h/ h. h }6 |$ o8 _% b7 K4 y* H. P9 k
} |