import swarm.Selector;4 J5 i' ?9 Y5 L
! i" F4 t1 B3 u1 d# M
public class SwarmUtils {2 q, D- S7 P w$ z9 @
public static Selector getSelector(String name, String method) {1 m$ W* W5 r% s2 C8 {
Selector sel;
+ s; s, _3 j, ~7 J. e! f try {' `& F+ Z/ J* f: |& D! i; i# R
sel = new Selector(Class.forName(name), method, false);
5 j* O( d! ~5 J! D" j# s7 G } catch (Exception e) {6 {% @4 Z6 C1 t( A9 j0 M( R( e) ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
+ F9 g# y: f9 e' S- n, { System.err.println(name + "." + method + " returns " + e.getMessage());4 Y% N Y8 E5 b9 d8 u
System.err.println("The process will be terminated.");
% h& i) z7 G4 d# m System.exit(1);2 x2 l1 f& B; A z4 R8 n, \: p
return null;' G% C$ ?( u, L! s
}
' G P3 \3 I: l" Y* y3 d% V! D3 X1 n return sel; H X' D. Y" u- o4 b" n5 ?
}/ S, N" p* q1 s6 o* U
! w& f i6 o4 ^: V
public static Selector getSelector(Object obj, String method) {
0 q- W+ y" C) b3 l3 L/ Y9 n( O9 ?. o Selector sel;
. y4 G% ~, [. b7 C try {5 f& ]0 n& j4 x
sel = new Selector(obj.getClass(), method, false);
9 c3 s4 |% ?- u# t- E } catch (Exception e) {
, ~" d* \" q4 b8 h System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " _: T# m; @) T! i' N
+ (obj.getClass()).getName() + ".");6 N# X9 T6 `1 |; ~
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());2 x6 `# e) w8 M; u6 F( ^7 x% |
System.err.println("The process will be terminated.");9 Z3 F4 v: D% h) |, s/ m/ a
System.exit(1);
/ S8 ?9 w ~; K: t: O. t return null;
% {: B1 p* g% A1 p7 ` S) V }" ]! I% o2 C- J0 w+ z$ s
return sel;
: F0 @! a. t0 s }
; K. i4 f. b& w" l! ?+ t2 T( E} |