import swarm.Selector;# g. W0 Y& e$ o, J4 L9 T
; S0 ~) [. z1 {+ Z1 w# V
public class SwarmUtils {
2 P9 S3 `. p8 \ public static Selector getSelector(String name, String method) {( `# j1 ]6 ~$ _1 Z) `0 a
Selector sel;6 {9 x0 `9 I4 T2 N; S5 N$ n! M/ W
try {5 ^; R, W. N4 w+ Z0 A2 v
sel = new Selector(Class.forName(name), method, false);% X% @% j7 t2 p) c6 H% X/ A
} catch (Exception e) {8 Q/ q. Z# _/ l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; P2 s x- `& R! W: a
System.err.println(name + "." + method + " returns " + e.getMessage());
+ M! g# Y9 y- c3 ?8 s System.err.println("The process will be terminated.");3 m- Y7 l% f" e7 r. y/ G6 x
System.exit(1);
- ~: a# V" F. G& e- \ return null;
& v" \: `3 z6 B! x: g* }+ c }
: p+ \- n. O G& k& g return sel;
) p2 U/ b P: e }
6 l" Q. h, _" M: x6 f; C9 E# I5 q# S2 W, f' {
public static Selector getSelector(Object obj, String method) {" Y# n& }) O* S2 D+ A$ c
Selector sel;
, K$ r* j6 A. }5 L try {9 ^$ ~8 N& Q1 @# V- \( X' u; r
sel = new Selector(obj.getClass(), method, false);
; X5 D( G0 b# Z3 S } catch (Exception e) {* e" `: L9 a6 Z6 X4 F- q% E/ \& v
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- O9 a( r' u4 L5 h/ P' n2 D. M- [ B+ C + (obj.getClass()).getName() + ".");
C/ ^: `' L1 q: } System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- A* a0 J. s9 [9 @) W& M System.err.println("The process will be terminated.");. E. }; ~" @0 s' @8 \; U
System.exit(1);+ u: B0 K9 _+ ]2 q$ z/ K7 P" F
return null;
) e {6 R3 r8 B( k8 i) Z+ p }0 `9 J5 s: V6 }
return sel;
! d ^" R9 n B9 J9 K' Y7 _& | }* o0 c! F+ d; o6 z% P% h5 h% B/ Z
} |