import swarm.Selector;( J" }# j7 L! m5 g4 ~) r
3 V- Y/ l; c5 o2 u8 q# m
public class SwarmUtils {( ~* ]0 F0 H" r2 M$ L- R
public static Selector getSelector(String name, String method) {
% }# U: t7 y( U4 f Selector sel;7 \# Z9 z5 S3 K4 r4 p3 d5 j
try {4 `$ D# a' O! @& u8 ]7 i
sel = new Selector(Class.forName(name), method, false);
" n6 ] N1 \. M } catch (Exception e) {
! e- q+ ^, }# N; o8 A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( _$ P5 }, j) ?) `: K
System.err.println(name + "." + method + " returns " + e.getMessage());
& f9 s" p ?3 q7 M* E$ v8 n System.err.println("The process will be terminated.");1 p# V$ v4 q, ~# h/ |3 k/ T
System.exit(1);% d% r6 N3 Z& y/ S8 }, h
return null;
0 Y1 g% W+ o/ Q( n, s }
# c5 ?; D, N6 @/ F3 k return sel;
, {- n( A! w! p% L }
2 A- h3 G2 t7 u8 y+ U) Y6 Q o2 Z' M% x( o4 ~7 d
public static Selector getSelector(Object obj, String method) {
% x5 E1 D- l# }, n5 C( a X Selector sel;
% P! v/ S( U9 [- ~- O! x0 c7 `$ o( {% m try {
9 r# i1 L A& E6 `+ [1 ^/ u sel = new Selector(obj.getClass(), method, false);
% d( n1 j& B; L6 ^( | } catch (Exception e) {
* B$ v! V; I6 t1 P+ d8 n5 { System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 X4 F# t7 f/ y; ?9 g/ G" E, d + (obj.getClass()).getName() + ".");6 E6 T1 F8 i0 }; t3 U: z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" r- L' d9 t% j H4 c4 h* F1 X/ O
System.err.println("The process will be terminated.");
_7 b% f1 m$ |, G w System.exit(1);" v' ~& c S; G4 g1 V' _- {$ p) x
return null;
' J2 h! V3 Y3 _( W' z9 Y }8 p! c0 F: ]; [
return sel;
1 r, x$ b( y/ n3 q, G% z* v }
! h! f2 U: X0 [} |