import swarm.Selector;
7 C9 O5 {+ B" P+ D: o2 h G0 q' t$ g3 v4 O0 P1 E
public class SwarmUtils {
7 f k5 e4 K, |" G7 W: X- E8 l public static Selector getSelector(String name, String method) {7 j0 K2 W! D0 f; O7 O
Selector sel;
" K; `6 X1 ?6 G, O1 S7 Y try {2 r7 Z0 r; r* L9 ?4 w( R9 B7 ~
sel = new Selector(Class.forName(name), method, false);* r" q3 o+ S. w& W0 _" Y
} catch (Exception e) {
9 ?- c% [9 s' w) p) Z* j System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");) L+ z7 O( x' s4 v8 k/ u3 Q7 I
System.err.println(name + "." + method + " returns " + e.getMessage());
. H% o% @+ \9 ~8 U7 e i System.err.println("The process will be terminated.");
- R) z" n, h$ Y System.exit(1);! A7 e. p3 I# I% l. ^
return null;& C6 s6 m& G/ f( B: \+ O( Q
}. @" ]$ e7 D' W8 P6 L9 f' C
return sel;
& T0 }" ^! r. b) O' ?0 Y }$ V6 g& m/ J2 Z4 m8 _6 i; ^9 @5 H
' t- R7 Z; e5 E1 M3 f# W' f# _ public static Selector getSelector(Object obj, String method) {/ ?. D5 I0 f9 ^" B6 ^/ E) o
Selector sel;
: b$ b2 p- M+ `* Z- c/ o6 Q" J try {
+ T j( u$ U4 q0 u% g sel = new Selector(obj.getClass(), method, false);
# @' b1 |2 E0 Y; `) Y8 A! r+ ~ } catch (Exception e) {) ?7 y+ g% ]2 X4 \
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 V2 T5 M" y* r" }/ U# T0 u' r4 ] + (obj.getClass()).getName() + ".");
$ w& m, i1 i; [& t: j& x System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' g$ B' g: t7 s6 @: u2 W System.err.println("The process will be terminated.");
5 s! s6 d" w+ }- X$ } System.exit(1);
0 b9 Z6 d+ S1 G( u; i return null;7 s5 U$ B* I6 Q, T) ]0 h' a" c
}
+ c c9 V- l( B/ q- f return sel;
8 n e; ~% D: A0 t3 \ }! G; w4 L$ t$ q9 {1 H" u! u
} |