import swarm.Selector;# A1 ]. H. C f$ }7 c" m
$ `. z3 M* k9 i! R) h% v' epublic class SwarmUtils {* E( H6 B) A# P2 g
public static Selector getSelector(String name, String method) {, a# v* T% P0 _) S( y
Selector sel;
q2 N( u v7 P, L( `, L2 S x) O3 f try {7 o- }/ m+ E+ b8 l; c
sel = new Selector(Class.forName(name), method, false);
! I" k* B$ w+ }9 Z3 N } catch (Exception e) {& V1 E6 N* h" j7 f
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; o5 e/ @: G L
System.err.println(name + "." + method + " returns " + e.getMessage());# |$ p1 h, m1 `0 D& p1 w6 h+ g6 d, b
System.err.println("The process will be terminated.");4 l+ p5 k' m4 F4 Q; }5 ?) o) Q
System.exit(1);" k. v& j' Q& A, o4 R- A6 t1 P! D
return null;
5 B: s0 v6 L6 C }" K) h7 ^/ ?$ S% D& d* R3 S
return sel;
5 _5 | y" \+ c: e. B. F# e- d }& j( U1 L% J$ @5 i6 x& O
/ J) a/ b% }! E& ^ X
public static Selector getSelector(Object obj, String method) {
1 Z# q# i- y: V( F7 Q- d Selector sel;
" |! F' }2 Z( y6 Z! }- y- J try {
) P' E9 M2 v9 _* t sel = new Selector(obj.getClass(), method, false);& c' I* m6 |7 J g0 f
} catch (Exception e) {
6 `$ Q" G+ z2 s% Z( W3 A0 u System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
; N# F1 ?# p3 {& |7 Q' h + (obj.getClass()).getName() + ".");
$ c; Q2 f3 @, N; v5 y0 y9 G" r) v System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 L4 d& q: g, q' i! p1 N1 ]
System.err.println("The process will be terminated.");8 u* o7 r( _! b
System.exit(1);) y6 G9 k% x8 R8 m( h- T- a
return null;
* ~/ z- w% H. H/ A# Z' c' i; d }$ T# b5 v L. I; i. N2 ]* \7 {
return sel;* B' k" d! `% u/ x& y% f3 z! M
}
! H! @. d# D; m8 R4 H/ }5 g} |