import swarm.Selector;, E; p8 {* O+ b
3 l# n% t; S, c* Q+ l% ]0 R' ?
public class SwarmUtils {
9 d+ r2 M" u2 J1 Y C! W' R7 P. { public static Selector getSelector(String name, String method) {3 j. x6 s" y3 C: Y3 ~
Selector sel;
7 H1 T" Q7 w; A4 |8 ~: O/ t try {
5 g( s. V% i+ X1 H; r; K3 U, L sel = new Selector(Class.forName(name), method, false);
. ^: K) D/ X' u2 d' h' D4 i } catch (Exception e) {
8 V8 ^" P' a, w& B/ ?" V' c/ A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 F3 K F8 o6 _/ ]3 \
System.err.println(name + "." + method + " returns " + e.getMessage());7 c5 q3 y# z+ W
System.err.println("The process will be terminated.");
6 t2 p$ d4 i8 v* O6 {) |6 D System.exit(1);
& ?# Z% m6 t: B1 i2 y return null;4 y1 B5 M/ p5 Y4 d* Z5 \, T
}0 |! ]# ~! g9 a. B0 S2 u/ p
return sel;: c. U! T8 K6 n
}$ j. d7 q1 P$ m+ Q
8 `2 E8 x+ p/ t5 a! L6 |, u" M0 w
public static Selector getSelector(Object obj, String method) {0 Y" ^8 @' p8 _; P6 Z1 D: l
Selector sel;7 w5 F% F9 u7 @* e$ f" h: D$ ^9 @
try {$ L/ V/ i% ^* K4 q
sel = new Selector(obj.getClass(), method, false);
( `+ A: P8 Z( Q! r, p } catch (Exception e) {
5 M7 N, }, G: U0 Z j System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' V# W5 `4 c6 @" d# h3 @ + (obj.getClass()).getName() + ".");
+ t/ k4 `& k: O+ c: X# J% |; w System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 R1 F& r: X* u6 q" f
System.err.println("The process will be terminated.");
# y8 B4 F+ Z/ D4 _8 l" N( `$ @0 s System.exit(1);# f }+ D5 d, {# R
return null;
0 }/ D% f, v. X9 M) v( L4 T }
3 h# \. v: |, n( c return sel;7 E! Q# A# [, C) G' e4 h T( r
}
, D: i _) L: q/ e/ q& @4 Z} |