import swarm.Selector;
0 o5 f' m+ \1 T- m7 F# E C% E# r/ y# V, D6 x& O0 a
public class SwarmUtils {
" ?; M& J% T# f* M5 Q! s9 y9 F public static Selector getSelector(String name, String method) {
" `; h; t) u7 V$ u6 X Selector sel;/ ^& a; y3 n9 v
try {
+ W3 ^7 A( E. N9 j6 J sel = new Selector(Class.forName(name), method, false);. S8 T: K! E7 p. ~: v
} catch (Exception e) {
6 f8 D% Y7 G1 g6 C System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
5 T& A$ A4 A2 K' }9 Z System.err.println(name + "." + method + " returns " + e.getMessage());$ d" v% c+ @6 I7 C& e2 K x# L4 i5 j
System.err.println("The process will be terminated.");
/ j/ }0 Q7 W5 o, n, w) J System.exit(1);
1 w! ]' p8 o0 _6 e+ R. M- A return null;$ G" \* P( H. P
}
9 ~7 s! j( v3 u return sel;- o! H% f2 F3 v* ^
}) [" m) t( N8 z$ ]/ G4 u1 x% q
; V' F1 W) k) ]1 g# V4 A8 X
public static Selector getSelector(Object obj, String method) {
; E3 C* y, r2 i9 u' ]- g Selector sel;% R" E" N+ H) Q. M5 O2 a8 }6 b4 O
try {
7 i: U0 X% h5 c sel = new Selector(obj.getClass(), method, false);
4 U1 e( q W/ D5 F [0 i } catch (Exception e) {
0 E+ L [% E# @: W6 y* X ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' B! U* K- ?+ a- g% i + (obj.getClass()).getName() + ".");% o8 p3 a8 c& O' k6 _0 f
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( F; W2 e' Q S$ ~9 o/ n S! ^
System.err.println("The process will be terminated.");
) H1 r: u" C! T) e System.exit(1);
B- c7 U9 J8 `1 }' w+ x% e& v8 d return null;
4 Q R/ p. L/ F+ a }
" F$ ]/ J; X. D# p- m( D" J& l return sel;
. A1 n1 t" i/ q9 y. @% a }
3 K. k! e" E3 U% L' R( v' n} |