import swarm.Selector;% D' l3 z9 j+ r& M o* n
' m8 D6 b H- i7 c6 Npublic class SwarmUtils {
( m2 F) y" P+ R5 `, k; u public static Selector getSelector(String name, String method) {
! i7 x7 M5 ^ n# C1 J3 i, @ E Selector sel;
0 ~* ^. |$ v4 r try {
9 Z; J. o, w2 Q1 v5 l sel = new Selector(Class.forName(name), method, false);! g7 ]9 l) S- H5 H# D8 X- Q+ e
} catch (Exception e) {
& K0 L9 t/ i: s Z& u; C System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
- d- k# E! g- Y7 q; k System.err.println(name + "." + method + " returns " + e.getMessage());
( ~7 d; F6 Z* i% u% f/ l/ k/ g System.err.println("The process will be terminated.");6 r+ I: Z$ s1 P
System.exit(1);
( @. I& {/ a4 E4 ?2 }8 o return null;
7 U2 }0 \3 r% k" G; |% n }
9 r; r: ]5 B7 U8 v% @4 Q7 B return sel;' C2 t8 H+ b0 h
}
( R+ g! z( a$ K5 Y% `* P4 t2 M- P) Q9 [
% j% j- [; |# Z" F, r public static Selector getSelector(Object obj, String method) {
) l I' }* X8 }- C2 H Selector sel;
5 x) P0 ]! F" A8 C% i2 j5 z9 Y try {
4 _- S2 y! k; c3 r; u3 V sel = new Selector(obj.getClass(), method, false); L u9 ^& @) e( f/ J
} catch (Exception e) {. ~- J) g4 G6 G' N4 F$ `, S
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ ~% M7 W4 U6 I4 c6 T: g8 K; ~" D
+ (obj.getClass()).getName() + ".");7 x9 Q; }" g) y% Q2 |$ u G
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' i5 F; _) {: o0 P% `- N! z; w% a System.err.println("The process will be terminated.");5 q" J& w# @+ ^5 b& h
System.exit(1);0 Z9 c- b& \; A& k/ p1 R1 O
return null;
) V* ?/ M! k8 h+ N' O }% g" |/ P' p! }7 ]
return sel;% I( B8 M; O$ Y, Z5 @6 F! _) n
}; R7 w$ }! c& }! u
} |