import swarm.Selector;
# a. M& X+ I8 x) V6 o3 Q7 r
* _( i' @2 S. d$ d* f; mpublic class SwarmUtils {
# |/ p* T$ @1 i' `. ]# i" m. x* W6 c public static Selector getSelector(String name, String method) {; |* \' f6 d$ y
Selector sel;
. I6 L# C2 G* a try {! ~ w f- q' k [" a
sel = new Selector(Class.forName(name), method, false);
% N" ^' d9 y: ` } catch (Exception e) {
. I8 Y, }. T" [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* C9 Y `8 }* {3 b! s1 N% k1 }! t System.err.println(name + "." + method + " returns " + e.getMessage());
6 w( p( k# u5 E, Z$ }( ] System.err.println("The process will be terminated.");
9 ^& D6 F6 o( @8 T9 v5 g& Y System.exit(1);- J6 Q0 D- ]2 N3 c: z5 ~# R5 \; K
return null;
' _: j- Y2 r2 S, k! H! d }
+ v5 {& ~* _: e7 L return sel;+ Z6 l! m% l. c# s# v
}
$ |' \- X. o& R. O( [- V; b6 ~8 T. Z
public static Selector getSelector(Object obj, String method) {
( o1 @8 s: @. S8 Z3 R* ?( d4 _* D7 v( G Selector sel;
( j" X, c9 S" T; d9 k try {
7 @" _+ z+ X1 I$ p" X+ l/ W sel = new Selector(obj.getClass(), method, false);
4 W& H& y4 r/ w' H } catch (Exception e) {
+ K* q# |7 {+ \5 i System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "0 ~1 f( ^ C! X
+ (obj.getClass()).getName() + ".");( | @$ p7 F7 ]
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 o( d: n2 [+ V' F% u
System.err.println("The process will be terminated.");
# h5 @8 H" I* o8 }. V( }. z# Q8 A; s System.exit(1);! D- D3 b/ \) _" A- j
return null;
^7 \8 o U& L! G' z h6 U5 V }
8 k/ P) Y1 S, A% X, {$ k return sel;
) c8 W, _, H/ @- J t$ } }
! O! D- `' Z- v2 O: N6 w1 R* V} |