import swarm.Selector;
! \4 @- F8 m8 f) o. g! r* A# f2 X) }" l) G7 ?+ T
public class SwarmUtils {( |$ M$ ~, m R
public static Selector getSelector(String name, String method) {7 ~& s3 U; Z% @8 Z
Selector sel;
4 [3 Q2 b' W: V5 ]* o1 |) I try {
/ h3 O9 k! s9 {, ] sel = new Selector(Class.forName(name), method, false);( A9 Z+ \/ a: G3 {
} catch (Exception e) {
! O& R3 w' ^/ s0 r( m8 o System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* I: J3 G8 {% u: _9 P: P7 Q System.err.println(name + "." + method + " returns " + e.getMessage());! N: L# x9 V- A) Y
System.err.println("The process will be terminated.");
c! v1 \8 n' A) D/ |. d System.exit(1);
$ q; Q$ O- l% ]% o( d& t return null;
: V1 W4 {6 a- r; i }
! @6 U* Y1 m2 g5 S; K return sel;
) }4 Z& r% ?4 m! e }
/ t5 ], c3 o1 M6 q; D
; a' \4 w# E% k4 ] public static Selector getSelector(Object obj, String method) {$ ~% K1 l ^! ]- y
Selector sel;
7 S* K' V* k& F+ K4 K7 @ try {
$ S. }3 O- N1 ^6 Q sel = new Selector(obj.getClass(), method, false);& ^: ?3 F0 m1 c9 u' }3 k
} catch (Exception e) {
. @1 a9 h% Y6 g* k' e9 M+ p System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ". P: v# v- W* _- x9 b7 z
+ (obj.getClass()).getName() + ".");
" a+ `" Y) H. z8 F8 c) H System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' K( K8 Y# R! k0 c
System.err.println("The process will be terminated.");
5 s3 V- v" u* r3 i/ q System.exit(1);6 `# v+ x+ k: J
return null;
+ H+ M$ u8 K- i7 l9 w$ A( A+ w! A }3 d4 M0 e, p7 {3 X! R$ S2 C; |
return sel;
/ {) k0 q0 k4 K4 [: J }/ n& Z; B2 e' d p4 l2 N
} |