import swarm.Selector;
& q" i* T" h( m9 e1 I) q# m. d3 s2 w- U9 g4 r/ v: R5 ^
public class SwarmUtils {
( k5 z3 I/ n& X6 J# h' @/ U3 D public static Selector getSelector(String name, String method) {
: n3 y9 V* _$ z: y$ f4 z Selector sel;) R" s- P+ h: \5 W' T
try {
0 T7 B6 U9 G2 t9 g6 X' p+ h" G sel = new Selector(Class.forName(name), method, false);
6 c, r$ Q) i( Y# K, ? } catch (Exception e) {, \2 A- W3 z' h3 ~/ X
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
2 M7 X- O# o9 B* O" b5 k% u) ?1 ` System.err.println(name + "." + method + " returns " + e.getMessage());/ C) H+ [1 c4 a* G1 \$ d
System.err.println("The process will be terminated.");4 v8 J8 d8 I- n4 H! l2 V
System.exit(1);$ Z7 J. C% N) L8 `( v9 V Q
return null;6 Q/ K/ [8 R V4 z
}; j9 [# d$ x5 h' k/ j% j, }
return sel;
/ \2 _& A" N# ?4 M K& [ }& ]0 |* `3 g1 N
$ W! U+ O3 s+ z! O$ X
public static Selector getSelector(Object obj, String method) {9 X) b5 c! R' P/ i
Selector sel;
" D' M/ e7 J7 n3 U; J try {
% w+ L" A- a) B; ` k sel = new Selector(obj.getClass(), method, false);& j1 M# |- [- p7 W
} catch (Exception e) {2 f0 {2 h0 U. a- ~0 M0 l8 b: S
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& X! o! Q& k; \) M; Z + (obj.getClass()).getName() + ".");8 @& K4 r6 o% X
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 n+ R# l& F4 b9 G0 Q; K: ^0 A8 d
System.err.println("The process will be terminated.");" n6 h. u& N) W9 o2 N# n
System.exit(1);
: g9 T* f9 m4 W2 G" i return null;: \& B% E0 M+ J$ C8 V; Q! E) o" v9 e5 D
}
. }3 d5 O5 O$ @! b return sel;
1 F# q' F0 e4 N- Q- S5 R( X- n# g }
! v- R& y% ]/ Y; y} |