import swarm.Selector;( k3 _/ X! t* K# e. a
3 X8 e7 R4 q- k4 F6 B
public class SwarmUtils {' u8 t, ]$ D) M/ X, O' ~
public static Selector getSelector(String name, String method) {
0 @) Y9 m# O. w* P Selector sel;
* C- q" S/ j: e7 C Q) V try {
9 A! J5 D8 Q% i/ V sel = new Selector(Class.forName(name), method, false);
. Y \$ d' @" D6 m( W+ l% ~& B } catch (Exception e) {" ^8 \- Y& U( g& f0 k0 R
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 w+ }# _5 a5 ~" ] System.err.println(name + "." + method + " returns " + e.getMessage());3 M% j' y9 }: J* N) e# p8 A
System.err.println("The process will be terminated.");/ _$ r/ b+ L% ^5 |+ {
System.exit(1);
( z! a9 ?3 f* ~$ \% a return null;
, m% B1 [& x3 M( Z# ?$ o6 p% X# m }( D: f) \" k7 F: g: r5 @; w; o% T
return sel;
3 W) z, L0 Z. c9 J q+ |) h }7 `" B* s: c+ [: u
4 q! S* F9 s0 t# G! s" g& v' d
public static Selector getSelector(Object obj, String method) {* X: j& f( n: t* M0 j
Selector sel;- C( U& @* x& n/ T7 p8 v' `+ s
try {& t) i+ F8 Q+ l( q( M
sel = new Selector(obj.getClass(), method, false);) [! b/ J: ~4 z9 G( }: a/ I
} catch (Exception e) {% y \$ N9 G/ n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 X. x' z* u* G3 M; L! x# ~ + (obj.getClass()).getName() + ".");
; @& T) W4 O% l System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ B+ C( z, d/ V
System.err.println("The process will be terminated."); @1 r( p' J2 c# s
System.exit(1);& h; f5 n9 W0 ^5 |$ a# L5 u. m
return null;
, V6 ?8 U0 C; [6 T c }" z6 g8 W3 X4 P! C! n, r+ `. V
return sel;
$ E' L3 O! y- y% N" \! V" n }! T. I# J6 w3 |+ `& r
} |