import swarm.Selector;. q& O5 O% {# J; x4 |; \% T8 z
5 K/ }9 B* X0 G2 Y' q; h2 u
public class SwarmUtils {8 H# k/ P5 [4 g' x% s$ u Q: T
public static Selector getSelector(String name, String method) {& p: e3 p% N) x' P9 h1 g" k
Selector sel; Q: m+ ?' N; G
try {! P' N* L' r& V6 u4 }
sel = new Selector(Class.forName(name), method, false);
- I( q1 g% `6 f. @ } catch (Exception e) {" b9 B' S9 x) b' A
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! `0 U6 G+ Y: t4 h+ l) f# f9 @ System.err.println(name + "." + method + " returns " + e.getMessage());, Y9 ^, Z. D, Q0 z
System.err.println("The process will be terminated.");
+ ?8 p7 f6 g- y System.exit(1);+ z/ d* L! m& J
return null;
: z1 \6 B2 A- r4 P0 W }2 @) ?2 r1 ~/ x* _- V4 g
return sel;
9 L' H, N! `3 v- ?. n }. O6 f1 R; m% E# K; s9 E2 _
2 b8 G6 G; z+ N" R" Q4 ` public static Selector getSelector(Object obj, String method) { s5 v. l; m- y1 P \. d" C
Selector sel;8 t! ]' b+ p5 v d5 o
try {, C7 w6 C% W$ a9 s* i
sel = new Selector(obj.getClass(), method, false);
, V: {) k6 n. c4 m* T2 X } catch (Exception e) {
9 z2 \0 E( o+ N1 z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" H) e, s6 q9 b( I& y1 z } + (obj.getClass()).getName() + ".");0 x n& w( e) Z8 S
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: ]% I5 E5 X% d, n; @, n+ V System.err.println("The process will be terminated.");
5 |. N# o' O2 m System.exit(1);
. B) A7 x& R9 {9 b# S& P3 R return null;
. w Z( Y: U. A& H3 R }
+ Y" Y8 Y! L8 ] return sel;
5 p! p* g1 h* K3 b+ J: p8 u }
5 X4 L. b+ C# e: V4 h} |