import swarm.Selector;! p7 {$ {& \ C; C
4 k2 o0 C; W; w# C0 a/ B+ ^& F
public class SwarmUtils {
7 e9 {' R5 ~7 T! O# B& R8 \$ d+ n public static Selector getSelector(String name, String method) {
: I. M3 T) t. m Selector sel;
/ P' S8 j- v' V) o' s. g. Y try {
3 y6 H6 R. C# j% Q# s( y8 x7 G* ^ sel = new Selector(Class.forName(name), method, false);3 l5 X! s' ]0 u) r' \( |8 L* ^! E
} catch (Exception e) {+ } W! ^& w' O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");8 q3 ~- f8 u& @( F8 K Z2 a
System.err.println(name + "." + method + " returns " + e.getMessage());
0 z+ W6 x' A9 u# e System.err.println("The process will be terminated.");
' L$ i* e" T$ Z% {0 ~5 q! l System.exit(1);8 \1 x1 [, A9 u+ c
return null;
- t7 c7 k. i$ ]& M/ _2 e0 A: |& b V }
' n7 u' g" C p* i8 n+ u+ I0 E return sel;
, t$ v# [# g: q; l6 W% g3 v } e2 Z; c8 L. K K4 }
& T9 J- ]* e& I. b public static Selector getSelector(Object obj, String method) {
1 J# N8 _6 }7 j0 R: r- U1 v8 a3 }& W6 u Selector sel;
: ~" Y7 ~' Y3 i( T try {
. [, w, s- N% [: n( J sel = new Selector(obj.getClass(), method, false);5 d/ r4 u( e( i7 H
} catch (Exception e) {
# I7 I4 D& V4 k/ P System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# j( N3 o& j! P# p* Z# u' I
+ (obj.getClass()).getName() + ".");7 G5 x1 u( I& z" z: x: |6 W \2 _
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 J4 f1 f& C: j @ System.err.println("The process will be terminated.");
9 |( L: ?7 C) C0 o3 J1 K8 \ System.exit(1);
3 V- \; \. i1 P. I) V return null;' g. J5 {5 K. ?! K0 I. a
}
) c1 e6 i4 U: p, s return sel;" G2 K) N& y" L- N5 C5 @8 u9 Z
}
+ m1 Z2 K$ t# l} |