import swarm.Selector;
8 V8 }, U1 E- `/ @# a, f0 h: F' C2 Q1 v, s
public class SwarmUtils {
9 y' }' W! X% @0 J0 i: Y$ z% a public static Selector getSelector(String name, String method) {# p6 F: v6 x# P; K. x
Selector sel;- ]* ]) o: h/ Y, r/ k# o
try {2 q6 D# @; A" t4 o8 T7 W9 z3 E
sel = new Selector(Class.forName(name), method, false);! g' l: v) e( ^9 R4 p
} catch (Exception e) {
# F0 E' A3 P; ~0 U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 p8 R4 O- d* \; E4 Y. M System.err.println(name + "." + method + " returns " + e.getMessage());
4 W8 Z+ H: u) q# u" u System.err.println("The process will be terminated.");
0 O% {8 G. U8 e System.exit(1);: n: O V- E! {
return null;/ Q7 U* X9 h& U- s0 J. G$ Q
}( d7 x9 m2 F4 N: `
return sel;& W' o4 Y( Z7 Z1 s, Y9 `
}; n9 t5 y1 D" z5 p2 f& F8 @) r
1 C' `# P+ h3 E; P! F! y! ?
public static Selector getSelector(Object obj, String method) {$ t# Z) U" A2 b0 I, Y% C* K- V J
Selector sel;
9 ^) ?; e/ r% j9 } try {0 R3 @; I* u: E/ F# H8 c4 L |
sel = new Selector(obj.getClass(), method, false);
1 N# G0 N( l' d$ L } catch (Exception e) {
& ?) g- I4 ? i4 b7 Q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& g. y. G0 j1 H( b! f, e" @5 R + (obj.getClass()).getName() + ".");
. w& h5 q' X) n System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# c/ S- ?0 \. H7 M! W' z$ M System.err.println("The process will be terminated.");
; E4 @% q5 Q [ System.exit(1);
: z0 W8 X$ _# f, n( ?+ J return null;$ O2 E8 U( S3 F8 Y2 w$ B3 i. z H
}
9 D5 b9 T! J, Q return sel;
' ^) Y7 {8 L2 c8 I& L3 D; o/ S }5 s, W% }6 f6 d
} |