import swarm.Selector;
$ v* D2 [( k* X. k% P6 Z7 A Z% n4 Y% @1 O
public class SwarmUtils {
: q3 R/ E- K0 Y public static Selector getSelector(String name, String method) {! q( W8 S" }$ b' Q, c, }$ r
Selector sel;
* [0 y$ s/ I6 Q: f. Z+ d7 f. p1 _4 V# d1 ~ try {
/ J1 p# ^& @+ d4 V5 d8 x" ~ sel = new Selector(Class.forName(name), method, false);
- B- `* L% }1 ^. p } catch (Exception e) {
! k3 [, Q- C" W- [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 a! @4 p. a% m9 X
System.err.println(name + "." + method + " returns " + e.getMessage());$ a" l0 B, f' w' @ x
System.err.println("The process will be terminated.");
1 J+ e2 w- f$ |: \' ]% W# {' _- N } System.exit(1);; [# O& H; ^& i6 W- _
return null;7 s s' a6 m4 p9 d6 y- d
}! [0 W2 d/ T$ s" _, S/ f a
return sel;0 j2 a) G1 g& H: r* c' i( J
}, ]4 `3 y F& J/ y% L+ i$ C
% P1 Q' D/ [& {. y public static Selector getSelector(Object obj, String method) {
3 A/ l& Z4 Q6 C Selector sel;
& F' B: q6 `+ @6 `9 C1 k try {
# Z. S7 v. @; @5 @8 k5 E* x* B sel = new Selector(obj.getClass(), method, false);! o) E y1 a2 \; z! O0 r( P
} catch (Exception e) {
; _# B/ [* ? h2 [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( Q, r- e, F, b% u + (obj.getClass()).getName() + ".");
0 {; H, K l- E System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 Y- t% N" i- S7 `! i) l* n; M* [9 ~
System.err.println("The process will be terminated."); l) W) d& P' L
System.exit(1);- p( E! N/ F7 E, X
return null;+ |% H9 {* p( l& V! G7 P
}; z; N5 K! X& q. Z/ j
return sel;& ?# J* y g1 d6 A8 H$ x4 p
}
[' v& P9 W! H5 T! u6 K1 q} |