import swarm.Selector;9 Y5 Y/ U- z2 B- R# G9 ^
: w T8 r, I8 m" K; k9 Bpublic class SwarmUtils {1 R- I6 l C" R* B4 g
public static Selector getSelector(String name, String method) { L+ x: x; V6 p' U' g( ~$ Y
Selector sel;- Y. A& Y p, P
try {. y: W9 R; O/ t+ p' E% G
sel = new Selector(Class.forName(name), method, false);
0 I, _5 c& d9 ]& M3 F$ X0 M } catch (Exception e) {7 T4 l$ ^7 a' n" F# l+ u' \1 z4 A% T
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) s8 E! y! T% f6 i6 o5 E S5 a3 } System.err.println(name + "." + method + " returns " + e.getMessage());
/ Z* e0 v4 `# T- Z System.err.println("The process will be terminated.");
) m* S- W$ Y* o/ m4 e' _ System.exit(1);3 |5 b* k5 E- w. }7 |
return null;
4 Z+ u) n* k7 g3 j+ r! ]/ Z }( A" Y' }7 J o6 O# ^5 t" j
return sel;# [; @! i% ]% ?% S3 G
}. ^% L. h8 R, |& F h
$ n9 G* u3 `% A$ {0 l l public static Selector getSelector(Object obj, String method) {
v" ^* p/ {8 t0 F8 }1 Z4 h Selector sel;/ } s& |9 u7 ~' L) w$ j0 K5 g V
try {
2 Z! y0 o# N% u sel = new Selector(obj.getClass(), method, false);9 _* ^9 [( I" E4 x2 g
} catch (Exception e) {! A' t5 Y4 X3 p. g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ Y; I9 k2 T% |4 E3 ~& ]% k
+ (obj.getClass()).getName() + ".");
) C9 M' p7 b L+ C8 a" b# Z ^ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 v" L4 N1 ]2 f2 B: m) h
System.err.println("The process will be terminated.");
9 x+ r: r# E+ q! | System.exit(1);
6 p2 |* R$ j0 G$ k return null;
$ h& f9 M4 U7 e' c5 R } I3 C' b- K) c7 F5 f: [
return sel;
) ^ f3 d) C; r! r5 O }2 @' _! ^; ^+ w4 j) q3 L
} |