import swarm.Selector;
3 s: ~* U& q% ?; N% Z3 c3 y
6 Q8 E/ G$ H1 Qpublic class SwarmUtils {2 O; q- r E/ d2 R
public static Selector getSelector(String name, String method) {6 Q9 C7 z6 ?+ G( b! u; L. K
Selector sel;6 M0 b6 h/ |2 b8 h
try {1 T! B* L* Q: i
sel = new Selector(Class.forName(name), method, false);. `- U' p) Q. {/ n" ?
} catch (Exception e) {/ G" e5 i* E6 h2 l2 c1 @7 {% L7 Z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" B3 G8 d" B3 E: v$ d3 W0 Q( T System.err.println(name + "." + method + " returns " + e.getMessage());
, N" [' E5 p" \7 f p System.err.println("The process will be terminated.");0 {$ F+ s, T1 F/ w0 D
System.exit(1);
% E6 {6 P! o ]3 b) {4 A( T0 R# y* y return null;" h2 o' Y; P+ t) m- T* Q, C
}1 R5 g. n! Y% s; H8 p; M4 P$ \3 }
return sel;
+ N$ i2 U) ^6 a5 N* B/ \$ X0 l) U }; B& N, Y9 {0 _ ?
- |9 r$ Q% }& r public static Selector getSelector(Object obj, String method) {/ x! A1 \! h( h1 E. X; U% H& I0 ~. u0 f
Selector sel;
6 Q# \, O0 W; ]! p w8 l9 Q8 m2 ]+ ^, m try {
% h( F |3 _- a1 D& Q sel = new Selector(obj.getClass(), method, false);5 o; k) Z) H# S! O& i A- Z
} catch (Exception e) {' ~9 l8 Y) R& B; V9 H9 b- G
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "- l7 d0 l3 R: k1 |$ w' {2 w- z& n
+ (obj.getClass()).getName() + ".");
; I6 V$ r/ Y+ N$ q1 X! o* n System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' B% p: w x6 O6 k System.err.println("The process will be terminated.");
( U- z1 r; _; j. k- G System.exit(1);
: [0 U( V8 l# l! A/ ]" u return null;
# K: U5 l2 C& {" g }
0 |; m N8 @6 n' n return sel;
: B1 t0 W' B9 h! ?& I }# [) f. \, s% b) r5 P8 m: b+ e
} |