import swarm.Selector;8 V' P8 Z9 S% U9 J+ {- W' u( z+ K
) h' d, o. `8 U! Vpublic class SwarmUtils {
3 W+ {- P8 Q% N3 L U/ ?" w public static Selector getSelector(String name, String method) {
% x( W9 E8 V" A7 u! v7 p0 F7 I Selector sel;
; N/ r: z o4 O Z! Z try {# S' x- ~" x" y0 J7 _% F
sel = new Selector(Class.forName(name), method, false);
) o' Y8 ~" m/ K: N* w } catch (Exception e) {
( B5 {" z( }& @' m2 [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* O1 f0 l2 z! H% \2 W8 y
System.err.println(name + "." + method + " returns " + e.getMessage());' ~, P" r4 {6 O( n
System.err.println("The process will be terminated.");
Z- N1 w# G5 d" h! m3 l System.exit(1);
! D3 {7 f2 D7 D: r- n return null;
$ B' p: [2 e# l w$ O }
$ O8 f' c7 f2 N return sel;
" H0 x! t, ?) E9 q F$ F }
& y, S" F# d. P- P3 d8 a1 O) ?+ U# q: v! F
public static Selector getSelector(Object obj, String method) {
[7 h u, O2 g5 f Selector sel;9 H; K* s8 h. O) o6 q8 w/ L
try {+ U( r- R1 P4 P* i% @
sel = new Selector(obj.getClass(), method, false);
! A; }0 c$ E) f* n M1 p } catch (Exception e) {
; k# }: Y I& r7 X9 t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "9 \5 O$ S/ }+ b5 k+ x
+ (obj.getClass()).getName() + ".");
0 ^ Z1 L) x* b+ | System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());3 E' d, l; ~, x9 ^
System.err.println("The process will be terminated.");. z f9 p, F% K k
System.exit(1);
) }! [5 L0 O1 V* e& Z return null;
% P Q( l- X* f' u3 |) D' u) Q }
0 @; m$ s' b/ K& U1 v3 Y" K return sel;
. R! p: u9 U) e# }5 N/ Y* X2 z, I" A }% `1 ?; A- z2 T. b! D! e9 L
} |