import swarm.Selector;
5 U9 G: `* j2 F7 d. W2 r: m& x' v& T% w' W
public class SwarmUtils {
% C' n! ~- H, A6 D$ F. U, n2 J public static Selector getSelector(String name, String method) {
; T) e+ s3 y: n2 `8 Q7 E" o; ^ Selector sel; u& x" d5 a! W2 D" L
try {1 Z6 \& U6 V: K7 P6 {" C
sel = new Selector(Class.forName(name), method, false);
- q' L7 z% e1 o0 Q% u+ D+ S9 Q } catch (Exception e) {' ], f: k J! v. V# h, }
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
^7 k$ x0 p9 r% Q System.err.println(name + "." + method + " returns " + e.getMessage());6 _- q1 A; ^) m! }
System.err.println("The process will be terminated.");
) v- i$ v' m0 W7 y& D+ G System.exit(1);' k0 F0 Z7 A+ ^3 _7 \7 e& X
return null;# _# `$ n6 J+ q, q+ {2 y: S1 n
}' s2 R+ k+ n& t6 E0 F+ J, ]
return sel;( x; x' F, E9 {( N
}+ a* Q/ u) X" z
* R7 _: E" n4 Y. \
public static Selector getSelector(Object obj, String method) {% V, n6 L) n5 }
Selector sel;
4 {. B" D6 q! @- b! d* j" ` try {
$ F3 D z2 S/ s# e: ?$ \+ o sel = new Selector(obj.getClass(), method, false);
% H! P5 u0 x! \. E8 w* [! X1 j } catch (Exception e) {( f! |' N$ z4 V% J9 h
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& x& g, E2 k# ~% K
+ (obj.getClass()).getName() + ".");
% ]; i# {% K- h8 \# i0 n5 c. R System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# S- h/ d# g0 c& C9 J& ` System.err.println("The process will be terminated.");4 D7 M6 L, O* `0 q5 I
System.exit(1);
* s( ]$ d' j& S' F return null;5 N8 _2 e7 o9 ~5 \- e
}( Y9 @% t+ _$ J, D6 |7 X
return sel;* h- W- \ j+ E
}$ @) `' p/ {$ W3 ~3 f
} |