import swarm.Selector;
4 I% v7 R4 X+ \7 H9 o
1 O3 K$ _! |. B& T. q+ opublic class SwarmUtils {
% \ j4 c1 A# c/ j& l/ e3 Z2 k public static Selector getSelector(String name, String method) {
j! M+ v4 t) _! N9 W Selector sel;
0 J6 d/ g: C! A. Z. U; z try {
$ z0 ?& N7 F( ~+ p9 K5 B7 p% @ sel = new Selector(Class.forName(name), method, false);
" |+ S: b. g4 v; p1 ? } catch (Exception e) {1 d% s; }4 i& ~! d
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. {# U( j& V- ]( p* x9 F$ t5 | System.err.println(name + "." + method + " returns " + e.getMessage());
" ~* P+ w) Q" ?: N2 L- m0 C System.err.println("The process will be terminated.");8 {/ @% ^: j7 T ^% Z& T
System.exit(1);
) q1 F0 }& I5 v return null;
) \# A" H7 J2 H1 a8 {3 M$ w9 q }
4 K; _5 ^; T2 ]/ l# @5 m! ]* l return sel;
! @4 Z8 o4 S l. C( ]& \ }+ a2 S, h( d9 n) M. P! R9 ]9 h
" O2 Z. `& A1 a( r: k
public static Selector getSelector(Object obj, String method) {& D& W2 |; t/ S9 s, Q& r
Selector sel;
8 X4 c: R1 U1 j* P. C$ A try {
8 t8 t% | D: F. D% R sel = new Selector(obj.getClass(), method, false);& t8 b& B9 b. L7 A1 w
} catch (Exception e) {
. M! T: r/ U: ]. o( T System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 S* V$ M6 Z" n7 q$ ~ + (obj.getClass()).getName() + ".");+ S5 `/ x/ k1 G6 r
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 j5 m& l9 a1 V) K/ X* ~6 t System.err.println("The process will be terminated.");; \& m2 I$ |1 v6 \' Q2 D$ _
System.exit(1); t/ ~4 h) A' g) W6 y! h) X, r
return null;
, m$ R4 E/ Z( x }: h+ C2 G- m% w. {. v
return sel;
" A6 D3 T, s; h) G& J0 c7 O0 u) H }
7 m1 S+ Z, X5 Z3 Q} |