import swarm.Selector;- U G# x/ T5 T. f, g
* _0 P6 ^$ N) S8 Y- Z0 Epublic class SwarmUtils {
, H$ m- E6 U0 t: W public static Selector getSelector(String name, String method) {5 i9 U0 I6 V, m0 n( T. ?
Selector sel;
+ C6 U3 B5 R; C try {
) z+ s/ w4 \9 N% N5 ^8 b sel = new Selector(Class.forName(name), method, false);, {9 g( ?8 ]4 T& b8 w
} catch (Exception e) {, W7 t4 z( f: f9 B6 r7 A" ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 p& X6 m8 p) U4 p) s System.err.println(name + "." + method + " returns " + e.getMessage());
; o2 w) {% [1 Q5 J# V/ w+ _- z System.err.println("The process will be terminated.");% ], C% p, a6 \( b
System.exit(1);$ W ]( }& E0 S2 Z: ^! D$ W: C
return null;
# u5 G9 \! X7 L! i4 F }0 n6 X3 P8 y" e7 ]
return sel;' P$ D) y3 T9 m+ K* U$ ^
}- e) M2 u1 C# U
; Z8 g# K/ `& d# H( l5 T' e0 ~) V public static Selector getSelector(Object obj, String method) {
/ W$ {- r; X: ~+ a& i. N, V- a Selector sel;6 r! h$ {) k1 e: T9 |
try {2 F' n, U( C/ Y1 K& L ~, F
sel = new Selector(obj.getClass(), method, false);; `, [, K1 k* ~3 p- }! y
} catch (Exception e) {
( q8 M4 Z4 D% Y' [3 q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ Z/ M; A3 M9 Q( C
+ (obj.getClass()).getName() + ".");3 { [5 D( T' p) p2 M x, L
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: ?0 T) U' g. H+ W# w. Z System.err.println("The process will be terminated.");
4 [+ I$ c% |! V System.exit(1);( V: b) z+ S$ G; i9 [% r" W
return null;
+ g4 r! i" `& P8 K$ K9 ?7 R }
- P4 l( Z4 {2 ]* H1 Q return sel;
4 e# n- E* `5 @( n }
% t6 T2 Y' l6 p} |