import swarm.Selector;0 {$ G" ?1 O# m- Q9 R
- Z3 r) s+ v3 U3 V$ u U2 tpublic class SwarmUtils {
/ Y6 S. D* E1 [6 ^' l public static Selector getSelector(String name, String method) {+ L }6 V' B5 ~% a8 [5 J
Selector sel;4 \; K) J7 M7 a# c) O
try {( ^1 A7 [4 {8 { V+ w9 C
sel = new Selector(Class.forName(name), method, false);
* O3 K! _. c$ w9 y t } catch (Exception e) {
4 p. | _) a9 D% Y& J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 [1 x. A) M! @ System.err.println(name + "." + method + " returns " + e.getMessage());
4 |: E, l3 q0 w u7 I System.err.println("The process will be terminated.");
# v( Y$ V4 `2 D: \. z% K System.exit(1);5 t& J% S6 T1 w8 L
return null;
" W" {0 E* y- R }8 W' l0 [/ Y$ n
return sel;
1 a1 z" N7 p3 I# d2 f' O }
. ~8 n9 A6 c3 ]* c& j( N7 k, t; Q+ o: b2 e
public static Selector getSelector(Object obj, String method) {
$ {- A0 p$ V+ X3 k! I5 n0 G3 T Selector sel;) s; n! F7 z- e: s4 G
try {3 D; c( [1 }7 I8 s7 E- W7 ]$ B( x; H( P
sel = new Selector(obj.getClass(), method, false);3 Y. k1 w [, W- @' i r1 R3 }
} catch (Exception e) {
. U9 `" l; Z5 h, m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "0 ]! }; ?6 F1 o3 K K1 t; _. V# \
+ (obj.getClass()).getName() + ".");
/ B! w& A# X) [) h* t/ N System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ s# p. o6 L1 {% a0 Y8 Z1 f* e0 O; `3 M System.err.println("The process will be terminated.");
7 d! w/ i) m! I0 s System.exit(1);0 v4 S q1 Z& p. n( [) ]! a
return null;: k+ T8 |4 e! F# J. H( f
}
5 A; X* T( ?( Y$ B return sel;% ]! Z" Z$ G% q7 @
}, C4 G7 l1 j$ _! r {! B
} |