import swarm.Selector;
" Y% w$ I( Q& X* j" \8 H" r
3 q. r! ?; _, t1 M# h0 u9 C0 K3 D# k" Ppublic class SwarmUtils {4 G" [$ t7 u- q* l, k
public static Selector getSelector(String name, String method) {
/ D, Q" s7 v' c Selector sel;
+ W: d$ V* v. ~6 W0 n7 | try {5 K! J9 z4 G& v8 Q
sel = new Selector(Class.forName(name), method, false);
" I& M; R' N$ ]4 N/ k } catch (Exception e) {
, ]+ D) |* G: J7 O/ E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");8 y7 D* i+ O$ Y# y+ x
System.err.println(name + "." + method + " returns " + e.getMessage());
T/ ~5 r j) |) W( i7 M System.err.println("The process will be terminated.");
1 Y/ S" z1 Q% d0 {/ t. l9 A' L( J System.exit(1);
9 |* K5 P9 D C% {; Q6 U8 T return null;! R8 i1 Y$ { g7 H
}1 I4 R; l9 Z, c# M" p6 ^- Z9 j9 s
return sel;; C& q- ?2 a( J3 i& `* r3 c
}
/ p8 F) @6 b7 q* L3 _/ p
7 C8 t' k- a2 o public static Selector getSelector(Object obj, String method) {
1 c$ k# e: J' U+ a+ Z# j, S* P Selector sel;
& x; I; p4 \, f% _$ T4 a try {
6 F3 R$ q9 H! e2 E- B2 h sel = new Selector(obj.getClass(), method, false);5 f# D% U) ^6 J
} catch (Exception e) {! L( b5 X1 n# g9 C, d {
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "3 u* H& |! C( P; W7 M c
+ (obj.getClass()).getName() + ".");" L$ r. W- W4 y: v; p! Y7 [
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, T2 u- A$ O$ [- c, p1 B R) Z0 I System.err.println("The process will be terminated.");* i/ B |6 p2 y+ x; P# w; I @
System.exit(1);+ u5 v& j7 W% y1 S) G. n
return null;
2 z3 W- S; l A+ S1 N6 X6 T4 m }
" x$ Q1 e+ @) `4 i; y return sel;$ L! }/ U) }) F" n5 V8 c0 y! A+ u0 @
}' x; m! ]- r: H, C$ W4 V
} |