import swarm.Selector;) J$ d3 l2 U" ] B5 O
5 b( q8 |. s8 w4 ~9 W- R: h
public class SwarmUtils {" N$ o7 W3 b/ V) X
public static Selector getSelector(String name, String method) {
/ j' d6 d6 q; N% ^6 M+ N Selector sel; x& U* Y" h" b3 X+ r. r9 ?
try {
+ Q0 B: {, M- s v; _ sel = new Selector(Class.forName(name), method, false);
4 u/ N- Z% D: ]; {% Z3 } } catch (Exception e) {
+ {8 R |8 q8 G- H System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ \8 z' I9 ]+ R- W System.err.println(name + "." + method + " returns " + e.getMessage());
$ Y* ^5 p. F. u0 Z4 T System.err.println("The process will be terminated.");3 O9 f3 z# p# M1 ~, K/ j
System.exit(1);
1 @6 ]6 V& S/ R: {9 `! m) Y return null;
V9 J; V9 j; I0 k4 c0 h }( r% M8 p4 v1 R3 h1 n/ e
return sel;% z2 e+ C. W# X
}6 ]: D+ b# Y. I
& q4 l/ v+ M' G! ]' C
public static Selector getSelector(Object obj, String method) {5 m0 s) E! |4 |) Q3 m+ N
Selector sel;
. o7 U& C# ?) D try {
; t: @% F( ]/ W/ c sel = new Selector(obj.getClass(), method, false);
, v) u( O$ x, T5 V$ q, X3 T6 [ } catch (Exception e) {
8 k0 R+ ], _% h System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ Y- ?/ R' A" x- r; F
+ (obj.getClass()).getName() + ".");
9 @) \$ z E5 K# k( Q# H System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ R0 }1 z4 R" g9 g5 q. O
System.err.println("The process will be terminated.");
8 r H# z; ]5 V2 T) |1 c( N$ z System.exit(1);
6 ?- v7 ^) b* h/ F0 {: J return null;0 y* Y- G0 d) a: e1 U$ ^
}1 b2 s3 H- U3 B% k$ j7 r
return sel;, X) I9 _. ^: W' e
}
j/ _ F0 Q0 u/ T3 `0 U7 V} |