import swarm.Selector;- ^' G4 d$ D3 y' H6 v6 p+ K- L! f
% \1 I6 [/ w9 Y; K' K; J; Rpublic class SwarmUtils {5 D2 G7 l+ X8 d
public static Selector getSelector(String name, String method) {
9 y4 M% U$ ?, S1 h8 K Selector sel;7 f. W ~* Y3 I. J1 b; k
try {3 u5 ]/ {/ F% K# R1 P
sel = new Selector(Class.forName(name), method, false);3 E$ W% N# H$ d* s' K, t1 y, H }/ r
} catch (Exception e) {
' R @& y }% m! g, L System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + "."); e9 B/ `8 R9 S: d! Y
System.err.println(name + "." + method + " returns " + e.getMessage()); U2 a6 j$ J% m! H% E
System.err.println("The process will be terminated.");
! M* @7 x6 }) o: {- ^ System.exit(1);+ I, I+ w; k; i5 h" A6 q5 C: c3 B2 n/ J
return null;( a/ Q0 t5 l V' k4 s: T+ b/ D
}
, t$ b6 p% l5 m2 v2 o: l i return sel;
- c$ H! [9 \: }( X }0 F* S% `: i& d: T. L9 H: A
- q5 K4 Y3 K( P2 A6 I# q
public static Selector getSelector(Object obj, String method) {
; S! ^( l n7 W Selector sel;
# w8 a: W2 T- u try {, T8 S1 Q4 W9 N
sel = new Selector(obj.getClass(), method, false);. K9 m0 W$ k0 U" K( @/ }
} catch (Exception e) {
9 S, V5 p, a+ C$ g System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 j6 }( d2 C4 u, {) u4 u' ^' T + (obj.getClass()).getName() + ".");& G1 C4 g% A: Z% Z# _* `
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 ~. e* q9 a8 v3 H& j System.err.println("The process will be terminated.");
) o w" S; |6 @$ q/ ? System.exit(1);% X8 Y$ R1 t7 e) S6 l& r
return null;, d( _* j6 X1 F. v/ k1 s* j
}
7 W J3 C0 J% A: F return sel;
. U) v1 I5 R! P8 V }3 j' g0 w3 ?9 H) c | E
} |