import swarm.Selector;
7 Q# V4 z* i+ T3 V( w1 w2 n
$ u. u$ n" a$ f- ]& Rpublic class SwarmUtils {
6 @ G4 j7 F3 d, k4 H+ d public static Selector getSelector(String name, String method) {
/ \7 X6 P* p* y. K; }' ] Selector sel;+ G8 K$ `! g+ C6 @
try {# \8 k8 ]/ c0 O( A9 F7 |- j8 q t
sel = new Selector(Class.forName(name), method, false);) i. h! x/ ?7 B; I* Z
} catch (Exception e) {
j" J$ W# Y; H* I9 O* m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# K( V+ y5 O3 b7 x System.err.println(name + "." + method + " returns " + e.getMessage());! q8 U2 r1 H$ f/ P; Q% o3 t# f
System.err.println("The process will be terminated.");
, q% x, H% B9 R$ O& q System.exit(1);
% ]; a# t: l$ j- a/ J return null;
0 y5 M5 N) L' j4 a% T4 B* q }
( J9 t* U9 `$ U4 N3 Y9 E& ~. a return sel;
% s7 N. {7 }: }1 N% L1 z$ `4 r }% K* @2 ?) w' q' @/ S6 d$ i: o
+ _5 ?8 y4 q# [, z! x
public static Selector getSelector(Object obj, String method) {0 ]; r5 L. R" l% f- B" i7 {
Selector sel;6 |% H/ K$ }) f5 O
try {
* I, [* T: B `0 R) ` sel = new Selector(obj.getClass(), method, false);- s, \ q5 E. j6 J- ~; A3 [
} catch (Exception e) {
6 X p0 {! g& @/ n! b3 a) E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% \3 M t% a9 E4 v# }' g+ X h + (obj.getClass()).getName() + ".");$ N6 K* ]3 r4 \0 ^
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 G' Z' ]; B1 a4 Z3 [+ X0 K System.err.println("The process will be terminated.");
# J5 K2 `. ]6 x! D# Q, V System.exit(1);
1 f$ {- g* h$ D% I: x return null;
2 a! y* Y3 J% f- v7 X }
5 F# a$ j, D# B return sel;
2 R$ R7 r/ H, p# B9 m" P* @( l: a }0 n( Z6 O' x4 Q5 J) X$ r) U ?
} |