import swarm.Selector;
4 A( ]3 ^1 R. N1 ]; G; u& ~$ {0 ]3 r; ?% C' {. q% i% s7 B
public class SwarmUtils {2 Q: T; X; c9 d% x. j
public static Selector getSelector(String name, String method) {/ G6 i( E+ {3 a T, A/ o
Selector sel;
% K4 r$ O" v U try {) B6 ]3 d" Y% v" D. O& G
sel = new Selector(Class.forName(name), method, false);
2 h* g; M& b! G& s } catch (Exception e) {
2 z6 S4 H# D" ^' U$ [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 C5 e, [# Q" @: Q! l! N
System.err.println(name + "." + method + " returns " + e.getMessage());( s- n) j$ ~- c/ ?3 n# v- f' W
System.err.println("The process will be terminated.");
+ p: Z, E& e! c! N System.exit(1);
! ~2 g0 o6 G. W2 u W, {$ w' }( { return null;/ z! m6 S0 d, @8 R E- p1 J# t
}0 x5 Y4 z' F! w! f5 n8 v9 I, F
return sel;
2 X0 ?. `9 B+ I1 P) B: y* C }7 w- _, ?2 V6 \
( X F ]2 X1 ~+ y% y4 L4 |- s: n public static Selector getSelector(Object obj, String method) {
; A( O8 F! G0 z' k Selector sel;* b8 l0 N! ?! i3 s6 H0 Y% z
try {$ J5 g8 B0 u) I/ e
sel = new Selector(obj.getClass(), method, false);: v2 u, v* J' I/ v4 R
} catch (Exception e) {
. b' \& P- \% k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ ]0 I% a: I/ e# R + (obj.getClass()).getName() + ".");7 q& ~: F- k( H# j
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# X+ S4 [0 g2 ]9 w
System.err.println("The process will be terminated.");
) Z; v d ] l+ B% T System.exit(1);( u# O, Y; @0 E8 M0 i3 \
return null;+ j8 ^' h0 j! ?- q- `
}: |6 p8 S# u# W2 t7 u; }6 G* T/ d
return sel;
& b! Z2 @, K( x }+ H3 M; p5 H6 V: x; d3 A
} |