import swarm.Selector;+ \$ e. @' v& o+ f* M9 z4 F
$ Y% M6 A& ?7 B
public class SwarmUtils {' Z. D6 P1 V* _4 Z! ~9 q) F N: c
public static Selector getSelector(String name, String method) {* ?! h0 ]7 v' m7 W& i# h% R
Selector sel;
1 J; m( J9 t& ^2 Q2 Q( ] try {* n: ~; k( C3 q3 y7 ^9 ^0 r, C% W
sel = new Selector(Class.forName(name), method, false);, A9 ]( Q. P$ R9 j H H& z- _
} catch (Exception e) {* G4 \! k0 J0 J2 T# l' F
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");. D0 e: k8 ]* ?& E+ Y
System.err.println(name + "." + method + " returns " + e.getMessage());
7 r9 Z$ S7 d" } System.err.println("The process will be terminated.");( _: \: S# T- H
System.exit(1);7 w/ B- d$ u7 b7 R. c$ N7 m
return null;8 `- ], \( l9 k7 [/ j
}1 `* V- L0 O" S
return sel;
- t4 G8 W& S# T. w }
5 f1 Q8 H: O2 D: T$ `# r% |" G6 h2 x0 m
public static Selector getSelector(Object obj, String method) {
4 |, l& T0 n" q+ s( N, c Selector sel;
) Q/ r8 d+ l7 X try {7 Z: e5 d; j$ N2 {, P" i& z% y
sel = new Selector(obj.getClass(), method, false);
" Z! o/ z6 g7 [' K } catch (Exception e) {
Q# @5 `" A" X5 _- X; n7 d! V System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 V8 |7 B7 H8 U + (obj.getClass()).getName() + ".");- N$ K3 O& }* x# n
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
5 Q7 W' K$ @/ x) k9 O System.err.println("The process will be terminated.");
. E' ]" F# ?2 l9 @/ [ System.exit(1);
5 m7 I2 j) H" C9 W return null;
' @2 C& @; m; I; T }7 V0 c% Z% @+ |
return sel;
) X1 a& ^: ^6 O# B& K# k }
X4 O4 l+ W: I5 p9 A7 z( G# V} |