import swarm.Selector;
6 N6 L7 j4 R# d4 P' s N* `6 \
: I. w. e1 m8 d8 P+ M& X0 Zpublic class SwarmUtils {' t" }4 @0 o% @1 U5 V0 a1 R2 ?% K
public static Selector getSelector(String name, String method) {
0 b! j; ~" U! ^( v+ z+ O Selector sel;
5 R3 I+ h( X7 g$ H* l try {& H; I6 y5 ]0 P; h5 {
sel = new Selector(Class.forName(name), method, false);5 W/ a) x- o' o) C. f
} catch (Exception e) {
1 y& Z0 H) ?. Y0 p1 p4 d$ B, k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
6 K! t: i" j: J% a$ a' _ System.err.println(name + "." + method + " returns " + e.getMessage());
# v- ]3 y1 j7 {: s0 i4 g! h System.err.println("The process will be terminated.");
5 o6 S+ C1 X/ ~9 r5 A2 b7 n% ~ System.exit(1);
4 Y! T3 ]1 U0 x l1 c return null;0 f a" i- n, o- a/ _
}
- E' a& d( r) B7 F; m i/ I return sel;; V6 I# a0 c: Q' Z% T8 q% G
}; e" J9 r" N8 x9 q/ I$ t& n9 ]
0 R. n$ G) y$ C' [% l2 }9 W
public static Selector getSelector(Object obj, String method) {
. B9 W" R2 q4 f Selector sel;3 P" Y. h. D8 p; r, Q, r
try {
# d) z% Z, }% L/ ^; R sel = new Selector(obj.getClass(), method, false);% g7 V7 s! }, G: }- Q% F7 v$ E+ `0 E
} catch (Exception e) {; @/ e& P2 j! Y7 s7 ]) n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", x7 B" W: w- E* K8 F4 _; A' w4 { r
+ (obj.getClass()).getName() + ".");
. i: g5 J* j5 |& F System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% S5 A( V- S6 n3 U! v
System.err.println("The process will be terminated.");0 T% L l# B9 F& X4 a! \* c
System.exit(1);$ V# p, q6 e {# F' r( Z* l4 l
return null;
4 O2 j% B* M2 G8 s, p' f }
* x. u: l2 g# C return sel;
# z4 j3 v$ n3 Y$ W- _. _$ X }
2 K2 n; k6 \1 Z: F} |