import swarm.Selector;6 n& |& J7 L" o y/ r! E' ?# V" c
+ ?" \+ t" x: U4 k( j
public class SwarmUtils {
; k2 ?; E( [4 v% I; m6 h2 p public static Selector getSelector(String name, String method) {( k" x0 Z( B2 a& X
Selector sel;; y1 M% ^) V! E1 v8 r! S0 ^
try {# x% [0 a& Q* c3 c g! V9 j, s$ G
sel = new Selector(Class.forName(name), method, false);
" q9 b6 u; I. l1 K } catch (Exception e) {
5 b8 G9 t" x4 ^& Y: O9 x" E) [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( E: O1 G/ N" D$ c g! w5 K
System.err.println(name + "." + method + " returns " + e.getMessage());
) ?' B" T+ u* E$ T System.err.println("The process will be terminated.");; M' U/ W) ~' |4 ~
System.exit(1);& J. ?# j X; L1 n6 ]7 r. [/ M7 d, J+ S
return null;% g' A& ~- S/ Y+ e5 b2 ?
}1 i8 c/ g) r- \9 w Z/ T; F
return sel;: `/ L/ J* U; a4 F. m0 [% P
}; p/ ` U+ _" P$ m
7 ?1 R7 P& C8 @4 V6 o& p
public static Selector getSelector(Object obj, String method) {
' A" B- \ M% M4 s Selector sel;: R7 f1 B4 M1 f5 M- G7 ?0 h
try {
- m, N9 j8 N, s9 Z sel = new Selector(obj.getClass(), method, false);
. E% I: L1 ~, Q/ {/ c } catch (Exception e) {
) H$ i o7 \# ?" z. E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "* ?5 H4 X6 Y4 F6 u0 o
+ (obj.getClass()).getName() + ".");7 w0 t5 |4 o$ c) b6 X$ h1 ^9 T
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% x2 ], a2 E$ U- B System.err.println("The process will be terminated.");. F K4 X4 v8 J' E, `
System.exit(1);& g# l9 b0 l1 I2 e/ O8 r3 G# D
return null;) ?5 ~$ ~' G/ O' E! o. ^1 i
}: m7 S" X% |1 |' d$ V2 N
return sel;/ b% d, l g$ g2 M6 J
}& L$ z- k: A4 E: [
} |