import swarm.Selector;
* |) C3 D% O3 V+ l, X- N3 I2 n
S/ x, x( h/ Apublic class SwarmUtils {
1 f' p, e4 h) v u5 |- l# C public static Selector getSelector(String name, String method) {
2 K- u- }+ o* Q Selector sel;1 ?. L3 c4 B2 F/ F) z; y5 C2 M
try {
. j* N! t2 `! `( ?) b3 x sel = new Selector(Class.forName(name), method, false);
7 K/ A* y( d" k% |! i I3 S9 {2 L9 b } catch (Exception e) {
( j9 C9 z' r, k: b$ h System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
6 X: P+ w8 J" \2 a2 N System.err.println(name + "." + method + " returns " + e.getMessage());
; ^4 Z' {: y" B2 n9 t- m System.err.println("The process will be terminated.");+ k& J& g9 K+ V* L9 d2 d8 w; R2 D
System.exit(1);0 i' F: f& O( X
return null;
" [$ m6 E: W$ H5 a9 J }
# e) E) B! e2 P+ ^& t; m) Y return sel;8 h% g7 G3 X7 w; p) A0 {9 P4 J
}
~! U$ R1 g% Z0 C& U" z! c9 |0 U$ O5 c8 r$ g% A( a% N2 O
public static Selector getSelector(Object obj, String method) {$ D: ^( k; W3 \3 g0 T
Selector sel;
$ O @5 [3 L ] try {
- l6 ]# x5 E! h* c3 ~' {7 T9 | sel = new Selector(obj.getClass(), method, false);8 H& T; L4 g. v D
} catch (Exception e) {' y6 V+ W. `) j% R
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 z b2 H. G/ ?% a7 V! z
+ (obj.getClass()).getName() + ".");
, Z7 L9 X) R& q1 ^0 l( Y System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% }9 F1 y) c5 K( m
System.err.println("The process will be terminated.");7 R9 ~# {+ Z5 b$ G6 Z( [- ]. b
System.exit(1);. \2 k6 Y/ |. f
return null;% Z0 I) Z3 `/ r. x0 \
}
" L0 p& N' f% h4 @- n+ ^# X+ r return sel;
, D# ?1 r& a: W* K' U4 ? }" T: P- G3 {' w' v: U6 o& `, @9 y
} |