import swarm.Selector;9 r$ K* R l- R, P* B
" e0 o# j T6 D& e5 q. f4 e
public class SwarmUtils {7 M0 a% J, g, t7 I( v/ H5 I F
public static Selector getSelector(String name, String method) {" F$ j6 Q1 o! p4 O$ C4 H' f& S
Selector sel;7 q9 I# a9 Y# n5 X
try {
, p0 N7 O& R; r3 P, v5 c sel = new Selector(Class.forName(name), method, false);
2 v) L& ~# K* L0 V# d } catch (Exception e) { z' `% K/ J, S; L& u2 S h) {
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; a* y6 o$ s4 `; _7 w8 C: c
System.err.println(name + "." + method + " returns " + e.getMessage());6 L5 ~1 P7 C* l$ L/ R
System.err.println("The process will be terminated.");
$ l5 |0 s' H, V0 C- b' f& S: d" ^ System.exit(1);/ l* [3 l: t' z
return null;
/ Q" M! S: d, x: H6 W9 Q }
4 f+ `) W' E3 U. O5 q5 U return sel;' c& f5 m9 } g k
}+ n+ H B8 u! v
. W% Z# ^8 @0 Q1 h- A
public static Selector getSelector(Object obj, String method) {5 w1 v% R3 u2 y. g
Selector sel;4 R1 ^) n/ F* c( W! ~$ [4 N
try {
2 h& i% @! i( |9 k sel = new Selector(obj.getClass(), method, false);9 |' i' K0 P2 ^" A. i3 j9 [
} catch (Exception e) {" Q) g4 s# q+ g# e( ^3 H+ ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 Z+ R. k P" X/ H: ^: b% x7 w
+ (obj.getClass()).getName() + ".");
' @- B: P' G/ g1 U System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: W( N+ ]4 n6 s$ _2 \
System.err.println("The process will be terminated.");
. z3 i& X# i5 v9 y) q( N3 E9 H2 \ System.exit(1);+ t5 s: P9 ]8 z2 Y$ L, x5 d0 C9 P
return null;1 B3 h& } Q% L# R! _# y8 C6 ^
}
* _6 Q3 K8 b! j' `- G* E return sel;
1 R# k+ R2 l* {& {9 h R3 Q! b }; t* v. }* f3 ? n1 Z/ L. e
} |