import swarm.Selector;7 J4 J3 T& E. J/ C
9 f6 b- w. p" b. r y: Z- J4 {8 _
public class SwarmUtils {
6 l0 y4 f7 J' Q0 n; L* J public static Selector getSelector(String name, String method) {
% f* U* K0 `, f. p1 a9 G Selector sel;# o8 p3 F8 D0 G" u( S
try {
% d) X6 \! V% f j. ~! P" K sel = new Selector(Class.forName(name), method, false);7 D- N% Z, M7 a5 q* E5 x
} catch (Exception e) {7 X+ B# V' h5 b8 o- @: a9 l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");' i8 Z# h$ k0 q+ U9 b5 u% P
System.err.println(name + "." + method + " returns " + e.getMessage());
: V" y* M; h/ |) ~2 I5 t+ c1 Y7 p System.err.println("The process will be terminated.");
, g7 J5 ^8 c; U2 ^7 C" a System.exit(1);
. ^5 u8 E' u: C( B# x return null;6 d2 D' Z& p, I \ \: Q
}$ M F" |, w" \/ G2 X
return sel;
. Z7 ^+ C1 k' T [ }
^! i% f! K: n, C$ z, Q4 S% u# m0 G# t4 y7 g( Q
public static Selector getSelector(Object obj, String method) {
5 Y* H& L+ X# w m$ n Selector sel;1 A8 V) s, m, [- n! B3 E: Z1 n: M! P
try {7 S) {/ D% J V2 R2 O; F! m
sel = new Selector(obj.getClass(), method, false);( d# z# w. f1 w- V/ d/ `) }
} catch (Exception e) {! s+ y; P8 e y
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
z. {9 q! A0 J. w" [$ L0 J + (obj.getClass()).getName() + ".");5 E1 I! y C9 J
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); [. M5 O7 q1 _) S) |
System.err.println("The process will be terminated.");
# [9 |9 t4 M+ V System.exit(1);
8 |! y6 }) a$ `: a2 R: l return null;
1 \) d8 }% q* E0 e" [7 | }; r/ I: N) @4 y. ~$ Q$ T/ q
return sel;7 T% G2 a R9 }1 D" C
}: [9 |' |! w6 C
} |