import swarm.Selector;
4 L% _# _$ @0 h# `* M% T/ d. x( P5 f5 X/ l5 P" l
public class SwarmUtils {9 I5 g0 k) n) A( r% ~0 [
public static Selector getSelector(String name, String method) {2 m1 @6 Q) e. R
Selector sel;4 @6 T$ Y2 N: _) V1 h' K2 V
try {
" I V( B1 z! O1 w sel = new Selector(Class.forName(name), method, false);
8 g! X1 P7 y9 P2 x } catch (Exception e) {7 z3 ~; r; ^. J; {
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 Q' c" P+ p. I
System.err.println(name + "." + method + " returns " + e.getMessage());
/ r K9 X% p# [% i7 r+ { ] System.err.println("The process will be terminated.");$ z6 B; j7 C0 N8 `
System.exit(1);" j! [8 w/ ~% Z. `. U8 _4 N
return null;+ p1 j: c: n. G: n) [; m+ p
}) |5 v6 \6 D8 a& n
return sel;/ e! C! g6 b4 }# f4 }2 r: D
}8 G# _# e) h$ k+ G2 e& {& N
' ^+ P8 c$ Y8 h. f- R1 P* }
public static Selector getSelector(Object obj, String method) {# |" z0 l0 {! T- T; r% ^
Selector sel;
- l) g/ G: L1 _$ j1 e try {# W/ W) Q) [! U$ p3 T$ T% J! A
sel = new Selector(obj.getClass(), method, false);
6 L5 a* Y$ g$ }9 b" D# L- W7 o } catch (Exception e) {
! O8 T' b) t, D2 i8 k/ f System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", W" _& e" n* r3 a
+ (obj.getClass()).getName() + ".");. U: ^6 d3 ^# \: l7 n
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: i4 u: H$ u0 E1 R B" T System.err.println("The process will be terminated.");! c- q& x3 c. W, y4 F1 w
System.exit(1);
( X/ c8 N7 H# N! M( T L! U return null;; |" }" d, F; c3 g+ B0 ~% G5 r
}
3 J- e- S+ i. [0 W: m2 q' X return sel;
- U" a6 [: U5 T5 l }1 p! J4 x# v2 g& F0 w
} |