import swarm.Selector;1 K" I( F7 e3 E6 T
4 D1 G8 Z r8 I$ a O9 W6 w; e8 l
public class SwarmUtils {! v3 p& X5 W$ d2 h, H4 `
public static Selector getSelector(String name, String method) {$ X& @% _) c1 O. u, I/ i
Selector sel;5 _0 n* M8 g4 T' g4 r4 B8 O
try {1 W# f# D6 J ]
sel = new Selector(Class.forName(name), method, false);
. D& W, ^! Y$ P2 g( o } catch (Exception e) {6 Z& z6 A# D$ F* ?$ ]* s2 X% {$ ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. a, p" Z1 k# G" x! k System.err.println(name + "." + method + " returns " + e.getMessage());
, c; ?0 L$ T7 e+ z; B System.err.println("The process will be terminated.");
4 S* t$ ?0 g8 R* J System.exit(1);6 w7 z' Z# g; O
return null;
( Y% x- i% R3 w9 s8 |8 _ }
' l* H) O, d& o4 c return sel;6 c! G* ^+ n+ H
}
1 w! E1 A1 C' G
# A+ i9 X: w5 p public static Selector getSelector(Object obj, String method) {; j2 J/ l% L, J; V# Z( n6 ?; o% [
Selector sel;2 x) K; L4 v) A5 y$ I6 d
try {1 `7 f6 U- D2 F' C# L; x) O
sel = new Selector(obj.getClass(), method, false);) r' j& X5 W9 `; A4 Y# w- P
} catch (Exception e) {$ t0 r$ `# {, t1 ], y, S
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") i' ^) o1 B$ E5 G& l. @5 ?
+ (obj.getClass()).getName() + ".");
( Y' A/ A/ R$ s T% M- m System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( {& X2 K. F! I$ O1 R
System.err.println("The process will be terminated.");$ d- p2 Q! B$ Z# E$ p9 T
System.exit(1);
; S7 w! v( L: g, C8 [1 ? return null;+ q' e x' Q" @& C( {( C- X$ s
}. p0 O8 h: Q$ H( L' D3 C7 g
return sel;
) j% A: A/ q8 h: z2 s! O; p }
- p" f- L8 M3 K, S7 E C0 q} |