import swarm.Selector;
; Z/ K1 q2 S9 _! j
0 I" H& g+ q3 u, C+ X5 Kpublic class SwarmUtils {7 y, e% G) ~( m* `$ n1 ^' ]
public static Selector getSelector(String name, String method) {, J" ?. ~3 W- g
Selector sel;8 [; {" d$ R' \; ?3 l
try {3 X/ I$ U$ W/ S- u5 d6 p5 m
sel = new Selector(Class.forName(name), method, false);
9 w. v- m" H* f- m } catch (Exception e) {
' i8 f1 }( f; E. }3 c System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: o3 F! B4 L# s4 _+ A! a# a2 J. ]9 B1 D System.err.println(name + "." + method + " returns " + e.getMessage());. J) y8 Q+ h; D8 x/ M, ~
System.err.println("The process will be terminated.");% E) ]$ `8 P: b4 `7 B
System.exit(1);" N x- X' O3 R! M$ p8 c
return null;
0 X- ]. E2 T O+ r+ |. V }
& Y$ u- |2 H$ _' `0 C" e return sel;
& r6 v( n: U/ _# l. X* W$ o }, K4 H* P5 N) j3 G3 k+ |
: z: q& w/ n& q P( X public static Selector getSelector(Object obj, String method) {
% S- F5 O% U' _7 g7 x Selector sel;
5 ^4 a: R) {7 ~' \' Z5 \7 { try {
; N' b% J- D1 @3 T6 v9 c% E sel = new Selector(obj.getClass(), method, false);' S# I7 E- S( O# A; Z1 @! H% u
} catch (Exception e) {9 z. y- W# d# d. a ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 q9 ^# c# N' O4 b% t* W
+ (obj.getClass()).getName() + ".");5 }# C/ E5 d! g( }" r
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ j/ N! x( u2 q% g& x# R* `2 N" G System.err.println("The process will be terminated.");- `1 g. f {1 F* v
System.exit(1);, ~; K8 G0 I% h; G6 x
return null;- b% g, {, h4 b, c% y. v. K" w( u
}. C h6 ?: Y7 \2 [' |7 m: Q* {1 y
return sel;& Y$ }1 {: h! k: {4 I# k
}1 v+ ^ A0 S7 e& l) B6 p
} |