import swarm.Selector;' n5 [1 j: ^4 z
% l/ J4 z Z; a
public class SwarmUtils {9 \0 W: g6 V, ?2 z) ~2 R
public static Selector getSelector(String name, String method) {
# Z; u' l) `- f' t' a Selector sel;! s0 p Z& F a+ m: h1 ]" l
try {
$ ^* G) N% J4 T" ` sel = new Selector(Class.forName(name), method, false);( t$ v# @! ~* N+ c0 e0 i8 ?$ ~$ c- u9 X
} catch (Exception e) {
" J* g( ^+ l( r% L System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# |: {. A; g: w& C2 X0 ^: X System.err.println(name + "." + method + " returns " + e.getMessage());
. \7 _9 y' {4 y U' q System.err.println("The process will be terminated.");
% x- w7 U2 j5 X! Z2 c2 ?1 ^ System.exit(1);
; n) k( H8 }5 [, S, m0 g/ o7 [1 G return null;
, a) t( u5 a$ _' V }& b, I0 B! K. Z" A7 c
return sel;
$ k9 ?; N4 h" d) J; I+ } }
( H8 o* D4 Z0 C% [- a5 W# P' G5 R
2 q" Q8 {8 W- `6 [6 { public static Selector getSelector(Object obj, String method) {; t3 x3 R* i3 H3 N
Selector sel;6 H! F/ A* E8 x! j2 ?2 D7 L# }
try {' a* A* j* `; b2 q% m- v s9 }
sel = new Selector(obj.getClass(), method, false);
, k2 x" `/ w" b6 t6 B1 O { } catch (Exception e) {; r* n' R3 E; e; g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "1 E* _; \8 u: F* [1 q; P3 u
+ (obj.getClass()).getName() + ".");' A$ m3 W: S( Y; f
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: K1 O E) T2 F7 w" \" J( | System.err.println("The process will be terminated.");
% I# J. x* @9 ^5 O: @2 G0 J2 W System.exit(1);
* ^1 i. H1 K8 U# r return null;4 J/ s6 G0 l: `* v7 M$ n. D4 ?
}
8 R7 p- N$ ~5 j7 A" j$ j return sel;0 J) v+ Q/ C+ C: y. s, S: z6 w" C
}* W% A! h* q, R" D3 ~
} |