import swarm.Selector;1 D1 H3 n7 v% A" a, j" P0 J
1 u M" [0 M: \1 c1 @
public class SwarmUtils {
5 }, R' O+ M( y public static Selector getSelector(String name, String method) {
5 X$ A; T6 A2 a5 P1 A+ T7 {7 ^ Selector sel;
6 H& c* O8 s' Z) |) v+ @ try {
B9 l. W' U, ] sel = new Selector(Class.forName(name), method, false);
8 D& y& C0 O$ s' O } catch (Exception e) {
; G6 n! \9 E7 }; V0 F$ _9 l) A: t* a System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");! o/ l3 f" x, h9 u3 [" T
System.err.println(name + "." + method + " returns " + e.getMessage());4 d# M& ? ]$ T0 M/ z' y* R
System.err.println("The process will be terminated.");8 [- O5 E* ^8 |/ T8 B1 k: L
System.exit(1);- Y0 q7 v# _5 t' c2 t4 r
return null;1 H/ l/ O7 ]1 ], G4 B! f& ^8 y: }
}
) W2 z7 }; H0 H2 P return sel; f/ w9 u- m7 i7 t( i$ R9 E
}1 o4 Q1 }( X0 N H o3 [! v
: L5 K# Z( \/ i2 P* H! c# `
public static Selector getSelector(Object obj, String method) {
, P1 v) @" l, G Selector sel;
0 q) I' a% G3 B try {
; x1 g x6 ~& i8 j sel = new Selector(obj.getClass(), method, false);
1 p2 E+ ^' W! g! g' ?; w } catch (Exception e) {
3 f" J7 S, \* s6 ^/ H System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") W2 x* q P9 z' \3 U& g
+ (obj.getClass()).getName() + ".");( }" ?( q+ i! _$ p
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());4 ~7 r7 T7 [, E. O
System.err.println("The process will be terminated.");. A# |/ U6 ^9 F6 h# W
System.exit(1);
6 g5 x, z) N9 _4 @. I return null;
3 g% t( [. k' l5 L5 Z5 ] _6 P B }
4 y! n( Z$ _% A8 H7 B: U return sel;
c1 w/ D, s [& O }
! B H* q4 L/ x} |