import swarm.Selector;
6 a7 f+ K o- X+ ^/ N
8 `. W+ T4 O% o7 N g5 |public class SwarmUtils {# B: ~6 g0 e5 G7 ]) S! { P& o
public static Selector getSelector(String name, String method) {# T1 f4 y! Q# K% f% i% W
Selector sel;
( M. _# y, y1 J* q0 P. b try {6 @7 v# V7 ?+ e5 O
sel = new Selector(Class.forName(name), method, false);# X3 j" L" i0 ], F& {, f& ~
} catch (Exception e) {
. d. f2 d3 B6 M4 X1 Q9 o System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");8 i5 r, W4 Y+ M. a" Y5 C) }
System.err.println(name + "." + method + " returns " + e.getMessage());
; V4 U7 @) t B# C5 `0 e+ D' n8 |. c+ S System.err.println("The process will be terminated.");9 |# N6 d$ [& O, P7 j
System.exit(1);
0 p/ ]# q: w9 j3 ]% `( K7 O return null;& O$ E' y6 `0 v5 X6 D f/ O x
}
" k2 k: j0 ^1 t) c8 O7 q3 n return sel;
* u% Y6 J; `$ v8 X* n# a. Z }4 Y% n" V% {7 {) s3 m* q
( A6 i6 u, w) W& d- e, j3 E% d5 H
public static Selector getSelector(Object obj, String method) {
5 B. F8 X( X: @2 N Selector sel;
3 S6 l4 X" w' ^; m q$ E try {
7 e1 N) s, L% f. i sel = new Selector(obj.getClass(), method, false);' g$ h3 P3 r m: M- y t
} catch (Exception e) {9 ^- a! l& E7 j: \0 `
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "7 v0 I9 u9 }7 x3 A- e( @% g
+ (obj.getClass()).getName() + ".");
: {. |$ `7 L2 u* V9 ^ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ a8 S; D3 v+ G% @. M System.err.println("The process will be terminated.");
9 G( \5 U/ R! U" T/ |& g/ W% X: t System.exit(1);' @& u- [) U6 }% t- [4 @/ G
return null; c4 n1 }# S, f K
}
) e7 x1 `! Q y" X! q7 m. L return sel;
s' F# K R5 O, H7 _ }# o; h# i3 G* G& \' n }
} |