import swarm.Selector;$ G, b& S- G* r8 y2 X* i3 N5 G% E
8 \0 b6 }/ S6 L* x8 i3 t1 \
public class SwarmUtils {$ h7 c e4 G( J0 |2 p
public static Selector getSelector(String name, String method) {
0 Y9 E; h& ~ Q# p* i Selector sel;& S& p7 `: S/ T6 Z
try {
4 E$ R! ?. S9 i4 a( ~# D6 ?; Q sel = new Selector(Class.forName(name), method, false);
! X X7 ]* k. ~. o } catch (Exception e) {( w/ u8 y z% B e4 a
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 C4 H j6 l. V6 ~
System.err.println(name + "." + method + " returns " + e.getMessage());: _0 C8 {7 u" k8 i3 o7 _
System.err.println("The process will be terminated.");$ H+ }- u2 t7 Z+ n- T& r8 z& o
System.exit(1);$ S* I8 R! m9 W$ A" g
return null; k) ]( T1 R7 O; w
}4 S. t: z" `* l: K9 t e/ [
return sel;
8 z; ]0 T* W! M: n( Q }
) X6 t9 ?/ C, }! y/ a8 ^+ Z0 R7 F; G! a& q0 U9 v9 q7 \6 p
public static Selector getSelector(Object obj, String method) {
5 J+ w3 d; x' t/ b4 c { Selector sel;* }7 E% b7 E$ X6 a( H& L X
try {
+ d* |! d" g7 `! U sel = new Selector(obj.getClass(), method, false);
% Q4 s7 a: p- e } catch (Exception e) {
6 w" x* C6 t5 r. _ B System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ d/ h! F/ o% f! @& e1 m# W" j- O + (obj.getClass()).getName() + ".");8 y, x& u9 H3 m5 g7 l; ~+ A
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: B" U- y! o' ~0 n1 K System.err.println("The process will be terminated.");
! m/ }3 l, U2 ^1 w% J7 I, ] System.exit(1);
$ L, I, w. b/ W/ J% \5 E return null;; m4 r- A9 x6 {) S
}
4 Y n( c; e( n: u return sel;
$ S! F) H) d5 x2 Y, ^* ~ }9 E/ ~! w/ p/ i9 q7 z
} |