import swarm.Selector;& ? E8 e9 P) O% R! J
% m0 W5 |. |& C" f3 B B$ a* ?9 vpublic class SwarmUtils {( [* H8 o" N$ W; i' r6 j
public static Selector getSelector(String name, String method) {
& L2 i5 S A* c; B9 A% v8 {0 ^ Selector sel;
7 I/ [; V1 R) B3 S" ^& z try {0 d" h. W# y; y# r e. i
sel = new Selector(Class.forName(name), method, false);
* w, q1 }$ @' @2 [1 W. h } catch (Exception e) {
: U* V* V O2 v: N+ d, I1 ?/ C9 e8 `! l System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");! [) I7 L; V$ x- g5 t
System.err.println(name + "." + method + " returns " + e.getMessage());# a Y% w% n$ n C
System.err.println("The process will be terminated.");
* V# n4 t4 D3 R$ P8 Q, i System.exit(1);0 z* o& w( F3 U0 ^+ d
return null;
& n9 O, S) X: }9 w8 B- D& i% y }
& B5 O/ R- ], a$ M return sel;
3 l9 ~$ X, ~* R- K7 ~* |5 c, e+ S) p }4 v; A( |, \2 G4 b: \0 \; \
# C: s% {1 l5 p! C& I, D1 W- q public static Selector getSelector(Object obj, String method) {
7 ?% f i( \+ m% S4 Y& w* z9 m+ w Selector sel;7 a' D3 ?" N2 V/ U- [0 _) u, P4 j: j! i
try {1 K% x. `* Z+ W- u! K3 K) h" W( j$ i
sel = new Selector(obj.getClass(), method, false);" S0 |, U. Y, E( J& ~
} catch (Exception e) {
6 ]7 J( @7 Q* X! ^ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 r/ }: E1 ^! f" O
+ (obj.getClass()).getName() + ".");
8 ?6 C% v, v/ ^* y System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ _. Y# ?( z5 O" [ System.err.println("The process will be terminated.");
5 \2 B( Q8 G& X* P, F- N7 Z: } System.exit(1);
) n! k( x3 ]1 } return null;9 Y2 ? U2 R0 h5 V7 l7 n( w
}
" H3 H: g9 ?6 K9 W }5 \) q: q return sel;% ?/ h0 W1 H/ n2 `6 }9 V' p0 h+ K
}- |% C6 {! l8 J) X! s, a
} |