import swarm.Selector;6 _' x- ~4 _' i* p8 M2 W3 S' v
% V7 S) c% N3 C2 z8 j
public class SwarmUtils {
2 _" X- Q! R- G2 g9 D! k/ x/ W public static Selector getSelector(String name, String method) {
8 z' @) h- q& j0 }) ? Selector sel;5 D; g: L8 u4 a. ^
try {: G! ^0 J3 N8 I# e; h0 b
sel = new Selector(Class.forName(name), method, false);, w% l& d7 Q' ~/ A1 Y
} catch (Exception e) {5 t3 C+ m% K4 `) V
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 h: ^" j6 L2 |) a
System.err.println(name + "." + method + " returns " + e.getMessage());
2 J8 s" b; a, F3 y6 E' {/ R/ U3 s System.err.println("The process will be terminated.");- E- I- a' }' m: x* P ]& y. \
System.exit(1);
a+ X& v7 m$ n( T9 U return null;- p) y7 F( W. h) Z
}9 I4 G8 x5 ]- x( ~! \5 h
return sel;$ d2 O9 ^. Q2 q$ B
}% ?9 L. U6 b- F
8 K2 _( Z! J% K; C3 |0 F3 Z( l n public static Selector getSelector(Object obj, String method) {
) i0 o# H' ?) T6 I Selector sel;
' _2 x L4 _+ N+ j4 l" n try {+ N: f3 Y8 J8 ~" ~
sel = new Selector(obj.getClass(), method, false);
' q2 s ]" H) {- {" x } catch (Exception e) {7 F* c1 L0 T2 S- f/ Q$ ^6 w1 l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ A3 K' K$ m- t: u
+ (obj.getClass()).getName() + ".");7 \. z6 Z7 T# A; s
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% H) Z% J! l) I: S1 k2 r# Y8 J System.err.println("The process will be terminated.");
5 @. d, {( u. T8 ? System.exit(1);
6 @* ?+ G. ]6 q" K- Q9 C- A return null;2 ] G- I3 I5 ^7 k9 F3 N% O
}' N' t& `9 R6 S; L. e2 V
return sel;
! Q+ i* U8 A: w! M- m9 F6 m }* I* ^+ T! }5 H5 p3 q2 a2 B; j
} |