import swarm.Selector;* m6 f( ~! L' @2 e5 S5 N( U
0 ?9 @2 x" ?; h3 _; {
public class SwarmUtils {! S0 ?- E( Y' B" j: b6 T
public static Selector getSelector(String name, String method) {$ I3 A0 ~# K% I7 ]. f8 G% G* Q
Selector sel;2 H$ H, x Q4 {2 ]# I; r
try {
1 {/ Q8 d$ I- J7 v1 m" O ^ sel = new Selector(Class.forName(name), method, false);
6 j9 Z3 J! e2 W } catch (Exception e) {
7 _6 k% A$ _, m) H$ ^; Q) O' x; R* L$ e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: M; i/ _0 B. A" P h3 E System.err.println(name + "." + method + " returns " + e.getMessage());+ K1 z. l* k. d# ?0 ~( c
System.err.println("The process will be terminated.");& z1 f, S* Z% J$ y
System.exit(1);, m, A) Z `0 r7 o; i s) C
return null;
5 g' K* Z0 m0 _. _/ G2 S1 i! f }9 n) k0 V8 y& e+ u/ ]: M$ F
return sel;
: }9 _# \' h! k% ?' F# k1 ] }7 e) J' }3 l% t1 O5 X6 }! K
; Y5 V$ ] [9 Q9 p- N public static Selector getSelector(Object obj, String method) {
; D0 N, V4 W0 |4 ?$ F; v Selector sel;+ X0 J" h; a" }/ I# ]' U6 {
try {
9 N1 T2 A) ~7 r' Q+ b sel = new Selector(obj.getClass(), method, false);
8 j( T9 n, G7 c, W" f } catch (Exception e) {
/ H, Z: j, g5 M0 `8 m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 r$ i, [/ j3 ? J/ M# L9 ^ + (obj.getClass()).getName() + ".");* P- k6 @7 k" S7 @# Y
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" l- d ^( m7 [- t- k* P8 Z
System.err.println("The process will be terminated.");* j# u h* L. ~' D( y) F1 a1 q% r
System.exit(1);
* w3 A3 W% u$ g return null;
! T i3 E9 n: B2 T4 b9 O }
! o% C$ F0 [9 i3 ~ G return sel;4 h6 [: Z* d2 i
}' h7 y8 C+ h$ j, F5 z
} |