import swarm.Selector;
. ], P p9 |4 D" b$ B/ O6 {& ^% K0 ~
public class SwarmUtils {
0 P4 ~4 l3 Q" ?' z/ d0 A+ U+ \- y5 G public static Selector getSelector(String name, String method) {$ l5 \ I, y O# k6 e% Y1 q6 ?5 O
Selector sel;! p; [ X3 l: I9 v9 l
try {2 X6 Q, _3 d! `, k" v
sel = new Selector(Class.forName(name), method, false);
* d3 Y) N3 b# V9 c8 B } catch (Exception e) {
, N) F9 K5 e5 t' h) K L, U) @) i System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 C2 l1 b- F/ ^; w/ z1 J
System.err.println(name + "." + method + " returns " + e.getMessage());
1 [6 h6 t" [. V, g+ R4 K System.err.println("The process will be terminated.");( e2 U5 F+ {+ l* i% k- s
System.exit(1);! H7 t# ]4 Y+ N+ h c2 G
return null;$ T$ U7 V6 D$ J5 D$ j3 J
}
4 c8 @* f; t5 |# L/ B) s1 N$ ~ return sel;
9 ?: {. U& M5 G2 O m+ e }
6 x2 n- `6 t+ J% `
# f6 V# c; d4 ^2 _! T4 o* l public static Selector getSelector(Object obj, String method) {
8 I$ A: T2 `- ]$ z# w) S Selector sel;( I" W+ \. @# v3 q4 {; r
try {# o( z0 S- A4 u" }" X
sel = new Selector(obj.getClass(), method, false);; _! ^" k5 @6 q8 F2 _+ ?
} catch (Exception e) {2 f1 H5 Q# {% O% @
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 Z$ b% u) b' I: I$ {+ s + (obj.getClass()).getName() + ".");. `& Z; w3 }! W6 v I8 _
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% B* A- z- g' B% L o System.err.println("The process will be terminated.");# t; } r! U" u# e8 B1 l
System.exit(1);. {; n6 u& i' t4 E2 y( j5 J
return null;
1 P, ]$ j" s2 Z. k7 b: E6 J( W* L }7 d: X: L7 h- U2 ?2 N
return sel;
0 K0 q/ O& c! R( ?" g7 j+ M9 k }
) m6 m+ H8 D1 N/ ~8 V0 R3 F} |