import swarm.Selector;- s- E! S/ y. [. q8 \+ X
" C: H" z8 u/ q* ppublic class SwarmUtils {
- c, Y4 N8 t5 L% h, o c0 J public static Selector getSelector(String name, String method) {
3 G* j& D- a& n Selector sel;8 `. J3 J' g# a- O# x9 L8 Z- ]
try {
. T3 d# {, ]- U2 E# |: d G sel = new Selector(Class.forName(name), method, false);6 h& I' D, v `- C$ n3 C# C
} catch (Exception e) {$ C! T$ X4 G, j" F0 W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; z0 ?! G5 L6 N: u
System.err.println(name + "." + method + " returns " + e.getMessage());
0 z$ ]! q( x+ {) y' p1 n- E( @1 a4 e System.err.println("The process will be terminated.");
# [" o4 G1 |# S" O3 k System.exit(1);
4 b5 m) _! \) q return null;
# x$ }; ?4 Y9 Q' I2 E& a; B" {8 N }
4 p6 K; z7 m) }' d return sel;/ u, L" m( G2 U3 Y' s9 }+ {
}" D. N& a2 s2 O- S3 v
; o; T! o2 h6 a3 |- R
public static Selector getSelector(Object obj, String method) {' e* t. s: e# o# E4 v; G
Selector sel;
# L: {" P: f* h9 X try {9 s$ M0 X$ K3 X- N
sel = new Selector(obj.getClass(), method, false);7 x; Q, ~% n# B
} catch (Exception e) {6 p1 Z! L. c" F% a8 G
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
, P1 x/ i7 |. h1 L9 F + (obj.getClass()).getName() + ".");) N2 F0 \( I& i0 ?$ U; J$ ^6 b
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());6 t! m; u4 v8 y. Q+ s
System.err.println("The process will be terminated.");
7 {( @8 h; M' _1 Q System.exit(1);2 Q0 H d3 p& U1 _$ b/ s4 U4 m, |
return null;
$ y6 F% G, y3 D% m }
- e3 B4 o! Q: b" o return sel;
, n& n( F, ?, g, V }% {+ j% k% J K8 j3 ^% t
} |