import swarm.Selector;+ f# d4 \( Q7 u
: X' w; i. ^' |) s$ Opublic class SwarmUtils {/ U6 i e( t( h- D, P
public static Selector getSelector(String name, String method) {
8 i1 h' m9 L- [# s Selector sel;1 }, D) {6 k4 z7 K
try {
# K% M: w3 g% S/ b8 I! S% E sel = new Selector(Class.forName(name), method, false);
/ [' ]0 e; ^9 o! ^! N! Q } catch (Exception e) {
5 d5 r/ R1 o% |4 u g1 V9 s System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");! T6 _% F) s" M, s+ [
System.err.println(name + "." + method + " returns " + e.getMessage());6 U6 l1 x0 ~: g0 R. r5 ~
System.err.println("The process will be terminated.");
+ g/ ~2 e6 p# s8 u/ \* Z System.exit(1);
* m4 z( b0 R2 \6 d# d0 A3 k2 t8 i return null;
- f$ g0 [0 t7 }! h5 d w% T6 X }
0 X$ C8 j2 }3 @- O return sel;
1 ] K# Y$ Q' `) I. x9 o }5 Z o6 R, Y4 l3 z
2 u0 B8 C' C3 C0 k! G public static Selector getSelector(Object obj, String method) {3 v8 G* X! y9 x. g7 l
Selector sel;
/ n" @- I! C1 B, ~. A" E! ] try {% T# C1 U; `; C: ]& S, U) m
sel = new Selector(obj.getClass(), method, false);
& d1 d& _" `, G } catch (Exception e) {
9 d' W. P4 D/ Q# g" `2 N7 a System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) g$ q( s4 f& o7 [$ O8 _ + (obj.getClass()).getName() + ".");; y; Z& D6 y- o+ P( a# P
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());+ k* {+ t$ S; s4 `: }, P2 H2 N
System.err.println("The process will be terminated.");
' T9 l) H( i7 N9 w. H0 l System.exit(1);
; {' \4 y0 h% ~& ]: R. H4 K return null;
" Q% ~2 V. Z$ T7 R5 o% E }) A0 ]7 f% T8 ^& j1 Z( I/ f
return sel;
# S9 F. P+ V# X, J$ ?/ \ } ~4 C n# `8 {: m3 @
} |