import swarm.Selector;9 B, d; C& p0 S* e) E. t+ d
& {7 d% x: h) D" _, y5 }
public class SwarmUtils {$ w Q# J* z0 m; |5 x' @
public static Selector getSelector(String name, String method) {0 ~+ t* a& t6 G) s
Selector sel;
& ], G$ F7 R6 j- n+ E" Z6 u' ~ try {
- c# P Q( A0 L) b8 Y5 u- d sel = new Selector(Class.forName(name), method, false);
7 x8 b$ R2 A6 t3 }9 ? } catch (Exception e) {
2 B( u; j$ y5 \. Z3 S# o% i System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
0 I' p: Y' ~0 X+ t4 e System.err.println(name + "." + method + " returns " + e.getMessage());
9 E8 o* k- c: U! M System.err.println("The process will be terminated.");
9 y# Z) p. U4 u System.exit(1);
& e& N& ^: y1 \; J+ { return null;2 G# j* v1 D$ {4 c! k
}! ~. p O! o8 e$ b% J3 u
return sel;1 `- h* {$ n* Q; i" A1 \# l
}
( F% X, f4 [6 Q3 P2 j7 [) O4 j4 W
$ o& C9 _( t! d" r% K1 G' \' Q6 M public static Selector getSelector(Object obj, String method) {
7 e/ L1 f6 [! f' n4 r7 @/ \5 ~ Selector sel;
4 e b- J) y# A4 I1 j7 c try {
. T. E& V/ \ X* [- E& b sel = new Selector(obj.getClass(), method, false);
$ Q: Q2 i3 P p/ @: W$ J } catch (Exception e) {+ k; e$ Y [& e' E/ U/ ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! @* `6 Q0 y4 I3 ^% S
+ (obj.getClass()).getName() + ".");9 i! E% m5 v$ Y* E4 i5 P
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); c3 A, W9 u6 w
System.err.println("The process will be terminated.");
: g, R2 a Z! e System.exit(1);3 u- X$ `9 t8 x# U( L! A, x2 O
return null;5 H; B# a: u$ v6 }7 [
}1 b7 `) W- B2 N- X t" G( A' F
return sel;
. ^% e9 o8 y' x6 ] }
% W1 }" c) F) d9 p' f4 `} |