import swarm.Selector;7 m' i; T+ ~* T
# G2 s8 R8 [, X, ?/ k. ~% C
public class SwarmUtils {
1 V' f7 _1 u ?! o3 t public static Selector getSelector(String name, String method) {8 \0 a2 U1 ^5 @+ z: M
Selector sel;
1 j& j3 P& {+ b; ?) Z" k try {
- W' e- `& f! v. r2 g/ ] sel = new Selector(Class.forName(name), method, false);2 t$ F$ s h2 h& v5 c5 l6 l
} catch (Exception e) {, q3 x! h0 @* ?9 E6 Y7 V# Z; e! b
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% c" B0 ]2 L6 o0 ]8 n6 ` System.err.println(name + "." + method + " returns " + e.getMessage());
7 b' p) j0 C* x' ~; ^ System.err.println("The process will be terminated.");+ E0 o# Q% L( N' a( e7 p
System.exit(1);
& `: [9 ^. _! |0 t" ^ return null;
- c1 a, {4 I( G/ k }
* g0 _4 m7 X/ K, g) w0 N return sel;
( [8 {% I( r7 C( D; ]' x }! J1 K9 m2 ~+ z
( F8 c2 j5 ^8 P4 K( E$ I1 i( ] public static Selector getSelector(Object obj, String method) {
, i0 t8 o2 [* R6 K6 f" e% f Selector sel;
% e. w4 h) m/ M( {# H try {! T4 E" \3 T& N8 [7 l- w8 o4 c) y
sel = new Selector(obj.getClass(), method, false);
2 |$ O8 `' w" c- F0 V" E3 Z. k; c } catch (Exception e) {
- j9 N$ K+ L2 ^/ O& H1 O# v9 L System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. h& A( c0 D" K& C, A& b + (obj.getClass()).getName() + ".");- ?# {" ~- f; l$ T% f) Y
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 [+ B* c3 _# u System.err.println("The process will be terminated.");' F. Z. |+ O6 V; {
System.exit(1);
" S; k6 g# a4 [1 y return null;. E1 l* }) ?" K4 W, Z0 U
}
$ K$ a$ I( G0 v$ w return sel;' z& @- o+ b' g O: Q( s/ c0 l8 o
}/ l$ R7 Z3 G* X
} |