import swarm.Selector;
6 c9 a/ H4 s: A5 A& {0 g, D# P4 |) f1 {. _
public class SwarmUtils {( b+ O% ]$ n$ o+ a
public static Selector getSelector(String name, String method) {2 ^! F7 D* s: j3 ]1 a
Selector sel;
. q1 I, K( w$ U7 B! z1 [" J try {: ]7 M: ` M. [0 d d9 K$ H* p
sel = new Selector(Class.forName(name), method, false);
" k l, e# ~$ x( h+ h7 h! } } catch (Exception e) {
) @6 b& _/ e4 l4 j/ M1 Q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% c' w" G+ b% N% D; T t0 w System.err.println(name + "." + method + " returns " + e.getMessage());4 Y E3 z9 b0 J5 m& p; Y
System.err.println("The process will be terminated.");- B0 l1 c; _( u2 M& N3 H
System.exit(1);
; n% e% E4 ]' X- g3 K return null;9 T/ a; n6 \; e7 @# p
}
$ o) p( g# @. b7 B7 z( {, B5 R* | return sel;
0 z4 G9 y6 i ]8 p) K }
8 o3 W+ M/ A1 ?" J$ ?1 }& |2 |1 B/ K2 d* a4 V6 t
public static Selector getSelector(Object obj, String method) {
+ d" G w- _5 ? g Selector sel;
k; z9 U/ E+ F! k$ x- I try {" I# C! Y, b5 b+ P/ ~+ v1 A8 U
sel = new Selector(obj.getClass(), method, false);2 i. {& R& c5 A1 o
} catch (Exception e) {7 l* E0 h9 @3 k; [2 m Q8 G9 [" h/ k
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "( T7 ?7 M {7 V$ l; q) o6 \
+ (obj.getClass()).getName() + ".");
* l$ Z' w9 ~8 b! d% Z3 v System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- V. Z& A% t1 ^: v1 ^ System.err.println("The process will be terminated.");& Y) ]) B( |' W4 f: A# _1 E& m: V! X- @
System.exit(1);
$ \/ X3 ?' }, P8 X' b$ | return null;/ O C, R# L' n- [
}
$ s" _* f0 n$ ^3 i, R, X return sel;0 A+ @5 R5 i* y1 q/ v
}
! \$ y( v$ M3 c! e- ?6 X} |