import swarm.Selector;
! o! ?; V2 x8 ^, f0 T6 M& h: X- S# a
public class SwarmUtils {
* R( v* {) U& P) } J/ k public static Selector getSelector(String name, String method) {
( P+ H! K1 V7 R+ S) z Selector sel;
2 l! ]# W; r* n9 i6 T try {; W6 w9 r0 q# t/ w( u) C
sel = new Selector(Class.forName(name), method, false);
# C5 U0 ?) [; O. Z; |: A/ H% t7 n/ o } catch (Exception e) {" t/ ]8 a: r/ g0 ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; L' Z) m# ]7 \- A0 ]2 _ System.err.println(name + "." + method + " returns " + e.getMessage());
" Q _& V6 Z" a9 Z6 ~9 j9 _9 {4 d2 j, ] System.err.println("The process will be terminated.");- G- A( g+ ], d+ h6 x! v- Z
System.exit(1);
* D, m( ]) i: ]3 s9 Y2 t return null;; V1 j/ {, ^+ V5 L0 y
}/ O( S6 w5 {# O3 ^4 Z6 j
return sel;
1 ^# A% k" D4 _ }
( I2 p( _0 q7 O0 N0 \' l; E D) x$ b o* Z/ S6 F6 }; T) A) a
public static Selector getSelector(Object obj, String method) {
7 \# L$ A s1 d' Q& S% M% V Selector sel;
, L2 L1 y! U/ i& \1 k; _ try {
2 Y ~, @" x; k& o3 }& E sel = new Selector(obj.getClass(), method, false);1 e: Y [' N) m8 b. B# w
} catch (Exception e) {, m& X# Q0 X# M% Y8 x
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " [- s7 l# A3 B. J: ^6 a
+ (obj.getClass()).getName() + ".");- h: j" K8 K* ?: D. A: {
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); c2 b. G0 I0 o0 h" g
System.err.println("The process will be terminated.");0 m$ b1 N! p Y4 @
System.exit(1);
, H: o7 r+ L' _ return null;! C" M1 ^1 J1 w% C W
}
% @) }! p$ |' v) M- X9 h( @ return sel;
e4 Z; W. D( Z' k, k( b" ] }6 L1 [+ h+ r2 Z7 G# E; N
} |