import swarm.Selector;% P* r) z5 I. T- j# ^! l: S
3 v$ D5 ~: E% I k) tpublic class SwarmUtils {* _5 v4 ?" H8 v- [- R
public static Selector getSelector(String name, String method) {+ \+ h+ v+ G$ d2 d: w0 F" k
Selector sel;# z6 J/ E, i* k6 u
try {
: g2 v; x' p5 `! b( V4 t8 P sel = new Selector(Class.forName(name), method, false);
6 s' D+ d% T6 M" T0 g* B( k: q } catch (Exception e) { u! Z1 @$ K/ x1 o) q. y d
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");. I) |& e Y8 h: _8 P5 V
System.err.println(name + "." + method + " returns " + e.getMessage());
6 N) Z7 h2 ^" ?6 i System.err.println("The process will be terminated.");
4 ?2 k0 Y) Q9 Z4 L System.exit(1);+ p" [# K! m2 A. v7 Y: x
return null;
1 b* N/ h( L+ M6 T; R) y }
. f+ H; i% C+ n( M return sel;
8 [4 m; e# c% N* _5 h } m* Z1 p K0 M% ]9 M
& ]) n" f% |7 N7 G- A% f public static Selector getSelector(Object obj, String method) {# L& N) A7 h) k- E) z, W
Selector sel;
Q5 T' E, `& V' l, m# E try {
! ^1 L5 Y7 M: Q7 \0 ~# C% G- h sel = new Selector(obj.getClass(), method, false);
4 T$ m s/ Y9 N9 j } catch (Exception e) {
1 `8 u6 l2 p& S. `% m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" e! `7 p9 |6 `) e
+ (obj.getClass()).getName() + ".");
- F$ V& {4 [% {/ G* f& N( [ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());& ]- V. z, u- Q
System.err.println("The process will be terminated.");
. f5 J, }! H. p) y System.exit(1);& {4 R" p* |" e T- S4 D% g7 G0 m7 I
return null;8 Y; |( x4 i1 j/ R
}3 G3 E! _" n! V7 Z: U8 `! c1 g9 W
return sel;* L; ~7 E6 v7 j2 C, z
}
& B2 e0 r- O9 G7 M/ Q2 C1 f} |