import swarm.Selector;
) z; K& a/ K7 l6 Q. e; d$ w `! _4 B+ J4 M% p2 X6 l. k7 ~
public class SwarmUtils {8 C+ _5 q% \$ n4 |7 S: M# C5 k! w7 L* _
public static Selector getSelector(String name, String method) {
3 j% p" U1 F) y. T" Q Selector sel;
, W9 @1 R3 m) q/ ~# l \ try {+ `$ A! R5 C6 K# A+ y, Y6 H* ~; K
sel = new Selector(Class.forName(name), method, false);4 }) V- F$ ?2 t2 t
} catch (Exception e) {
z6 d- Y* D6 U3 b, m) p3 \) @ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! w2 ~- o1 i S3 |: P1 H9 U System.err.println(name + "." + method + " returns " + e.getMessage());
; g2 ]% W1 r* m1 c9 a System.err.println("The process will be terminated.");3 w% q3 R, G2 N; k9 p. K8 x; u
System.exit(1);9 n; L+ E8 a8 ^9 j
return null;: o- r" b# E+ ]9 @0 K; X' y
}/ o" Q( \' i3 [. f0 h
return sel;
: Z* F; y# L, c0 y }
0 M6 S3 K. V8 P+ T6 |- S% d$ I4 D# Z( z5 f4 L- I: r3 ~
public static Selector getSelector(Object obj, String method) {
; C. \& k0 S! w: E Selector sel;
4 @6 s5 B" g# T" {; m+ M try {8 _0 J! g; |; K0 h3 U
sel = new Selector(obj.getClass(), method, false);* h |( k/ R' |, E# w# j, K2 n
} catch (Exception e) {
, _0 J& r7 z" q r System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 m5 p3 v/ P1 Y0 L- k% R( `, Q + (obj.getClass()).getName() + ".");! p; {& ?) U `1 d8 r* n
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());+ V" `9 |3 R, e
System.err.println("The process will be terminated.");
4 E2 O! c- }4 ~9 S" y( j System.exit(1);
4 p: r3 Q* l9 ^4 v( U return null;. a1 @; x, n0 @& t8 F" X
}
* L4 e- t7 U% d9 C return sel;% @/ V* H' V) M: G0 I
}
( \/ h* Y' ?* a$ r8 @2 \/ B- L} |