import swarm.Selector;. l7 S" Y" @( y( d* B
5 ] j% u& I( D5 h/ {+ _public class SwarmUtils {
/ l8 ]+ I) ^5 n+ h public static Selector getSelector(String name, String method) {
5 p. B8 R* p0 G$ u7 ~2 W Selector sel;
* m- N) [2 ~, ]6 q$ ? try {
" N( [( [) h' ~8 i$ R/ A% @. [, b sel = new Selector(Class.forName(name), method, false);" s8 Q& O5 J1 _; p2 b: n0 v% q
} catch (Exception e) {
, C5 O% ?7 l t2 H' N' E7 ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' z: G k$ a0 d6 m8 [! Y5 J System.err.println(name + "." + method + " returns " + e.getMessage());. t- C: D8 b1 v! X3 b! h, ^
System.err.println("The process will be terminated.");
, c) b, ?6 j- Z# \4 ?( V System.exit(1);
0 K. t9 {! b$ {; c/ ?% J) i$ B return null;
0 x+ ?7 S" x5 I# ~: l }
% T# _' B5 h- a return sel;
% e. Z( f/ A) y b8 V" O }
) g0 B2 C+ @/ G! T, A2 a z3 N. _/ ^2 d/ Q
public static Selector getSelector(Object obj, String method) {3 K% j' y+ z/ X* ?8 ^3 n" Z
Selector sel;" @: P2 }, `. y2 A' K3 A1 S
try {0 b0 H: M: Z6 G
sel = new Selector(obj.getClass(), method, false);
) {, {" |6 P N N4 l. D7 ^0 g/ y } catch (Exception e) {
/ }- I( \+ ?- E$ {0 a; @ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 l/ S0 W* Y) ?
+ (obj.getClass()).getName() + ".");
% R4 T, T* C# x( y- |9 g5 V System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( O% x- c3 U L5 Q+ Q- S7 e3 F System.err.println("The process will be terminated."); {0 x+ }4 x1 R7 d
System.exit(1);6 n* g6 g( G8 M* Z7 V6 K
return null;
" g8 A! Q A' N" Z5 b: N% J }
( Q8 ]8 c. h! {/ q return sel;9 J8 ^. b) M& t+ i, \$ b
}
& W- E3 K7 n; U" @} |