import swarm.Selector;5 ]! H/ W' I2 P
: n- e, K# v. Q& M; Cpublic class SwarmUtils {
) G& R" }6 S2 M( ^5 ` public static Selector getSelector(String name, String method) {
* D% L- P0 w U8 K9 F Selector sel;- s {2 a5 H) i2 Y* o, v; M) ^
try {
9 n, A8 O3 f( q9 R. U8 \! b! g sel = new Selector(Class.forName(name), method, false);, K( c1 i) R; W( r
} catch (Exception e) {
. r w+ Y; ^& m6 h' P System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");) G7 c0 T8 d( [: m6 D9 g% `
System.err.println(name + "." + method + " returns " + e.getMessage());: L' A# E" F& U: x+ P$ b
System.err.println("The process will be terminated.");8 Z+ O7 b3 e Q* A& z/ d3 W
System.exit(1);( A' ^' T$ ?2 S% ^- N1 _3 q
return null;( X+ D( i0 P& e! V! h2 e: g9 ^
}
0 {1 ~, {6 ~) j/ \* u( F3 @" l return sel;
: E4 v' w5 P3 w( ] }
$ t D; C: [& R5 {7 R; ] }) N, S$ b$ k
public static Selector getSelector(Object obj, String method) {9 a# k; K7 x* ~6 s; @+ v: A
Selector sel;. q2 f2 S6 M; S- R* A; q
try {8 u5 C! E4 D$ ~# Q8 Y0 H4 v
sel = new Selector(obj.getClass(), method, false);6 R: Z" y2 }$ ]
} catch (Exception e) {
8 L7 H) a' G- e) P System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 N/ b( j9 N, ]5 V: b, r + (obj.getClass()).getName() + ".");
% F1 h( P$ _/ c( K0 h' p" j* C, R System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 | I/ j% q7 a) d System.err.println("The process will be terminated.");9 j( [* G% i9 P8 G
System.exit(1);
' i7 {) [ h$ `9 P' X) ~ return null;
3 {4 e4 h8 c$ w+ I" B$ R }3 Z/ e; N( ]- o, |0 a8 a3 j7 Q* H7 K
return sel;5 e \9 U* w6 D& A9 T
}
$ \- I. y) ^4 R; F} |