import swarm.Selector;( y( h H$ ?$ p" B0 W9 C6 I, Q
/ r+ J' O& w1 O
public class SwarmUtils {7 M9 U6 `" Z; c1 J+ c
public static Selector getSelector(String name, String method) {
/ p% j" N- R' c5 n0 V) i$ j5 C Selector sel;
1 _! i: h6 r: D( \3 S7 Z: E7 T/ e( V try {0 \, [) z+ j- a3 \( X0 q: F' O
sel = new Selector(Class.forName(name), method, false);0 a2 y8 m' Q3 d* o
} catch (Exception e) {
5 ]4 q& i3 h B' Y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) ?$ M, k [7 ^ System.err.println(name + "." + method + " returns " + e.getMessage());
) n' Y& ^3 P/ ?8 M. j; e2 L System.err.println("The process will be terminated.");( B( ?% [2 I1 e/ m& h k( J
System.exit(1);5 ^8 Y0 r: g. |" l, o3 Q" U6 o
return null;. `7 A0 @+ m; Z* W1 `
}& a4 v/ b! q# k$ l, S8 d* B8 ]) C0 n1 K
return sel;
& y0 D7 B0 \$ \8 }5 I( F6 | _% I6 F }3 x' k- x- m) } j2 D) `
W7 [+ \* S+ V/ p% ~$ [) L: V public static Selector getSelector(Object obj, String method) {( a8 q2 F8 d% O" a
Selector sel;
) R$ |4 _2 I& W3 X& p$ r# M) v try {
" I7 z- `% J' _' {% T: H- k sel = new Selector(obj.getClass(), method, false);5 e; G6 }7 X t8 q# x4 _
} catch (Exception e) {
6 X3 x/ J) U; J, t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
* _% n6 k% g6 `9 y3 r; j8 C9 y) x + (obj.getClass()).getName() + ".");
; ~3 h2 c/ Z' X7 v- E System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 [/ h; s% w8 y5 q8 ]) w System.err.println("The process will be terminated.");$ C }3 v8 K% U
System.exit(1);
3 W1 x! o. Y0 k return null;7 T% X; j8 u0 l6 W3 o" |4 a: g
}
6 C0 f+ g2 r4 }8 s6 W$ m& ^" c return sel;, I8 d1 m h8 C8 q6 n
}# h: p- `" Y: \* d
} |