import swarm.Selector;
) l7 z+ a/ T: ?2 J# v4 o( a5 m
, \* A9 m' g; Q4 Hpublic class SwarmUtils {/ F. O. l% r# b! q* X$ j
public static Selector getSelector(String name, String method) {
( ]$ q/ R P# x: N" u Selector sel; {! h' ?# K2 N. R! m
try {
+ \4 m5 L3 G1 z% u& B% d% i sel = new Selector(Class.forName(name), method, false);
1 l) M7 a5 d6 \ u0 o; Y } catch (Exception e) {
0 h1 y% ^, L( C5 Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
+ Z6 [ b# K8 s, N7 b" z2 t System.err.println(name + "." + method + " returns " + e.getMessage());
/ d0 l% y: H( R$ d6 H. c$ P System.err.println("The process will be terminated.");+ u) z" U3 j$ A( J+ A
System.exit(1);
1 C7 |0 c5 | U& Q M+ O* c return null;
8 K) i7 X( l8 m+ J) e }
* c P! `+ i/ H4 G6 ^ return sel;
0 N) y* d9 s" v5 w& n }3 c5 b+ R7 I, J. f m
5 |4 Y% v. S5 i g" m public static Selector getSelector(Object obj, String method) {
/ I7 L& s4 }6 D Selector sel;, {+ O3 j. { `5 D
try {
6 T3 { ?) i* e4 m sel = new Selector(obj.getClass(), method, false);
. r) r( v w4 |1 T9 }% l: e } catch (Exception e) {
( Z: [3 u5 \' y5 ~) K) ~ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ y" o) a* x# W; Z6 t4 M + (obj.getClass()).getName() + ".");3 D% o0 R/ V5 c1 @$ O b$ f
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) m- g/ [3 v# a K, r3 p
System.err.println("The process will be terminated.");6 q; F" ^1 m- [0 D3 r) m
System.exit(1);) O+ D. L+ f# i; N3 e5 s( P4 }
return null;
; ?2 E( n8 ?8 A; q, } ^2 b* g# H }3 y0 _9 l v7 C% \% n( j0 `
return sel;$ b& v t8 C F+ m4 T! Z
}
: g, I# a# U7 O/ F! J} |