import swarm.Selector;
a) C" Z" F% S' l" A3 t j+ x) Q" O2 l6 ?8 p0 k, P
public class SwarmUtils {
5 m- Q2 ?) G5 Z3 @. `9 c3 T1 M public static Selector getSelector(String name, String method) {
, }$ B& ]( o: @, h) s Selector sel;) o7 A2 S3 X L- a
try {2 `9 x c7 k6 i& Y/ k
sel = new Selector(Class.forName(name), method, false);( ^7 y# O' `0 B9 A% U& }
} catch (Exception e) {
% R* A( a1 h) k* Q7 z4 b System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( N/ x0 p( Y& h# n( ^; m6 J! T System.err.println(name + "." + method + " returns " + e.getMessage());# q! v1 D J J, P
System.err.println("The process will be terminated.");
- i$ l1 f% V$ O3 \ p System.exit(1);1 I3 T9 G! K' t5 ^/ B( P' \
return null;" ^5 I- Y, J4 R* R; Y) D* E5 g
}: b6 p) B9 K8 _1 I0 x
return sel;
" c$ g& f5 W2 W6 v" @& p6 ~ }) N" W7 F6 f& r u# `: L F1 W
4 q0 j0 N+ M1 j. p8 y. h public static Selector getSelector(Object obj, String method) { [4 n7 `# P8 j6 F6 j% n! w
Selector sel;) P# M9 f& W9 G* ^& E5 E6 D
try {. _7 g" j4 a7 r1 F
sel = new Selector(obj.getClass(), method, false);
. N0 V- l1 e( g- n6 W# \3 g } catch (Exception e) {; Q$ y U1 b$ a5 ~- K
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "9 Z. @0 l3 U- F% N
+ (obj.getClass()).getName() + ".");
/ f! M+ ^- _$ ?- { System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
" f3 n+ C- Y8 L0 M8 R System.err.println("The process will be terminated.");6 i4 A, _8 @, n# a% s! W% W
System.exit(1);
2 x+ ]7 V' {7 Z$ q5 S6 G; c- d return null;4 \4 G8 z5 d2 g% ~6 W
}
) `, J8 m7 l e: H; R; B return sel;" q+ E8 z& H u7 E+ k! K
}! N {) g+ W) U# n! e- R
} |