import swarm.Selector;5 t4 q7 s" [" V8 V! f
: M$ |( v8 U5 @* H/ P
public class SwarmUtils {
[8 k2 X5 E' p/ I4 R7 N public static Selector getSelector(String name, String method) {7 i# s* H8 s7 ?
Selector sel;6 A, R8 n# h7 K2 \/ {( k! l
try {' K8 k' i z1 a
sel = new Selector(Class.forName(name), method, false);, p7 n" z; G& E+ ?7 L
} catch (Exception e) {; m6 S) d7 K4 E3 L( V9 ^
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! y9 E$ P* B* [2 Q' l1 T7 a! |/ E8 f System.err.println(name + "." + method + " returns " + e.getMessage());
' `8 U, B5 n/ }# ~7 [$ l$ y System.err.println("The process will be terminated.");0 U0 L9 `* Y9 ~( m( u
System.exit(1);
9 h, S: {) B; I return null;5 }- q$ y! B: n5 w+ k
}4 `2 A) X4 x; p
return sel;
" C, p% t* D4 ~ }
. ?# r4 m- q# a, Y! o3 |' K3 A# L" w+ g7 `6 w$ x5 u
public static Selector getSelector(Object obj, String method) {2 y% W- E+ Q/ u4 g! D9 {$ i. ~
Selector sel;
! ^ b; N, |8 Y, G; q try {+ h( W4 `/ l+ L$ Y9 } }5 i
sel = new Selector(obj.getClass(), method, false);5 p+ Q' m3 h! S* v: ?2 c8 v
} catch (Exception e) {
) N8 h! ?8 j; `& Y! b System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "1 `( A/ Q2 t% k" f) X0 k3 p$ Q6 _
+ (obj.getClass()).getName() + ".");8 X6 V! D0 c1 s* U, X
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
! u& I; d5 P% P System.err.println("The process will be terminated.");" K8 v* F' \1 e8 _: Z
System.exit(1);) D" S7 r* X/ [+ c, b$ Z" u
return null;
6 W) I, x! \; p/ f: }( N; M }7 d$ V% [9 b6 A" p
return sel;
$ _& ~3 S! r! P2 H7 S }
# S/ S. z+ M; R C5 W+ M} |