import swarm.Selector;9 u% N$ P# k$ Q0 n+ L
9 H9 S* R8 O( m
public class SwarmUtils {
( Q2 w. W8 W! g8 r- S V public static Selector getSelector(String name, String method) {
0 v2 c0 {% T6 T3 [- o! _: Y; \, @8 M Selector sel;
* D p6 |! {0 T; p! w try {* P, Q g2 I: I# J4 d, E9 I# B
sel = new Selector(Class.forName(name), method, false);7 y" h; c6 S, Y( g: c
} catch (Exception e) {$ D% X# Z; j: D+ }9 H
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
, G3 N5 J3 u- C7 y5 \3 N3 |) ?( D! q8 V System.err.println(name + "." + method + " returns " + e.getMessage());
+ ~8 I- V8 W0 @6 C$ u System.err.println("The process will be terminated.");% G- b3 u; X) l: t# S" N6 C2 M
System.exit(1);& ?, a2 S& K! j; q/ R' W
return null;
5 M2 c C0 g. \- Z' G8 u }+ {. k" S* J& K9 P+ a' L/ e
return sel;7 L9 C! ~' p" z8 B
}! C3 c' c6 p1 W, L0 T+ s
2 @: F* ?" b7 Z public static Selector getSelector(Object obj, String method) {
" r! R8 C; S9 }7 c, z9 ` Selector sel;
' m3 n2 q6 y6 \; G, E! T# m try {
$ d2 d; t x' O4 U! n3 X sel = new Selector(obj.getClass(), method, false);1 `1 I u$ ~! O, B' n3 C
} catch (Exception e) {0 T! ~% k y) J' g0 z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 e/ l. u+ t, J3 \* f N + (obj.getClass()).getName() + ".");( P6 k9 J1 r5 @2 ~4 M: A. w
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! q) }& J# _$ Q
System.err.println("The process will be terminated.");1 H* p& x0 A; w" M' q
System.exit(1);5 L3 I$ n# }) D8 i
return null;
9 `1 c, G. |& B! H5 \" h* G5 o }
& a2 X9 H* z' f+ B0 ^4 b5 F return sel;( N$ T+ I/ \8 W( ~4 ^$ H
}
( q5 T& ~4 _' Z$ y& b! m} |