import swarm.Selector;; d* K& F' E. G1 D; h9 F
: ]% x) a% r2 ?' r+ ?' g9 W: g& tpublic class SwarmUtils {- r! L* d+ k$ T6 u8 b4 j6 B. }
public static Selector getSelector(String name, String method) {) L$ r7 X3 f( T7 Q) j6 v+ t9 H
Selector sel;
. S7 g p6 f2 G try {# R5 C/ Y L1 E: ^
sel = new Selector(Class.forName(name), method, false);& k w, ~- a) S6 W- z* x( l
} catch (Exception e) {
& Z2 i7 r' J! a# m% g* ] System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");' j& G3 q6 I* y/ N( F. Q
System.err.println(name + "." + method + " returns " + e.getMessage());
7 B5 I7 N/ ?; N1 e/ @' M$ f System.err.println("The process will be terminated.");1 _" _8 t8 x0 ^1 G% R& n
System.exit(1);
3 s4 @9 @' R& p* y return null;3 B+ z G2 a, _% W6 m$ R0 i( a( D
}
0 W2 J$ o( p) N5 ?7 F! q return sel;
" w5 z5 R5 T9 X3 U# B7 e+ x }% j5 }5 i0 i8 d# s' e% u
: y, R: ?5 u( X _ k
public static Selector getSelector(Object obj, String method) {
( v* j. V" y$ n; Y1 T0 q! {9 U Selector sel;
8 [8 @( h$ ~. Y3 j( Z7 f try {
$ `) {( p1 d/ U4 O3 m sel = new Selector(obj.getClass(), method, false);
% _3 t, H) n2 _ } catch (Exception e) {
) L9 y5 `8 N! ]9 H( t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! o9 h3 z$ O& R + (obj.getClass()).getName() + ".");
0 K$ P) P8 R$ d7 r System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% O0 O, ?2 X% d D8 W2 s' L System.err.println("The process will be terminated.");
0 O1 B! A' N( Q! R& O System.exit(1);
- H( A) T% g: x/ z/ @ return null;
7 W8 J) ^) {3 [4 } }
$ a( H; E7 V% Z8 C+ P8 w return sel;3 q) I* L6 k! ~; f3 Y
}
1 I9 s$ g4 v! I$ Z0 d: P} |