import swarm.Selector;4 l) d$ Q, s$ w5 K) T) [, l
* d) v4 _4 ]4 ?( y' x
public class SwarmUtils {; E8 E. z/ ]4 C7 q C+ p" x
public static Selector getSelector(String name, String method) {' [) n+ [; i+ A
Selector sel;0 f' U9 G ^8 ^4 q
try {& p: s. u# N$ Y8 K
sel = new Selector(Class.forName(name), method, false);2 P2 }) ^2 b4 n
} catch (Exception e) {/ c4 a: c% m8 L" n& S; s
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( _' x# H+ k3 y7 f
System.err.println(name + "." + method + " returns " + e.getMessage());4 X8 {2 v4 m3 C) H8 q
System.err.println("The process will be terminated.");
9 ? ]9 i' _0 e6 l4 V6 A System.exit(1);
: `7 g. k" `, f% q% N, p return null;$ O3 L- W' L! l- Z8 f1 i
}+ G( E5 f" p! d+ ]/ {
return sel;
3 A: m, m# l$ G, {5 l }
" w( w" U) W, c: n# }7 Q$ r/ g: B, t! ^. `) F, Q1 z
public static Selector getSelector(Object obj, String method) {2 q K* ]. o. \5 ]0 j. o1 y
Selector sel;
% P! J. [/ E5 l `8 i try {
6 [+ ] j( W& K& P- Q& V sel = new Selector(obj.getClass(), method, false);
% F# L8 l" r* G4 q } catch (Exception e) {
) v" F( N4 H3 i9 O E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "1 o( y8 {" o! H" O! w
+ (obj.getClass()).getName() + ".");2 w5 Y1 w9 Q" j r/ z+ E
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 V: U# u% V! O
System.err.println("The process will be terminated.");
: C4 u* O* E; P2 u System.exit(1);( E: ?4 ^9 G5 \# v
return null;- ]7 ?2 n1 ^3 c* O& J
} X% V/ V: k; M7 e0 ^
return sel;' C. u; C8 g; E* N+ f, C" v# @+ l4 T
}
, h% ]% ]1 v5 G5 O4 O} |