import swarm.Selector;; Y* w- k/ s+ E# y
+ q7 ]4 s1 [- D, Opublic class SwarmUtils {0 J$ p9 m( W. g6 E: T8 }
public static Selector getSelector(String name, String method) {7 }# i- c# y1 d/ i" j5 ^* q8 z
Selector sel;2 v4 r# `! K; Z8 K( k% V) B
try {0 e, h8 d& }, P2 {: I4 }7 Z( y/ W
sel = new Selector(Class.forName(name), method, false);) n+ }3 k4 X" x! D w0 c; I
} catch (Exception e) {2 X5 w: \& X0 |% N
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; z: _$ o) ]$ n+ r: t1 l
System.err.println(name + "." + method + " returns " + e.getMessage());* F8 N) {& E6 r0 B# F1 M' ]- [
System.err.println("The process will be terminated.");) @3 N. X2 b, s7 Q c1 B
System.exit(1);
9 O& l* N) r$ r! \! s9 I5 D& p return null;
' I0 `5 C) V6 z8 M. @ }. S- Y; T+ M$ k8 k6 \* N9 z8 j
return sel;
% o: X& t; k% U, x! R! e) q6 Y }
6 T9 z- A' p" p9 c" [3 F$ G: w" u# T
# B- {. R2 E8 j public static Selector getSelector(Object obj, String method) {' ] v0 }) j& j8 w r* X
Selector sel;
Y, q) k" Q6 ?/ E* Z" K try {$ A0 j; E- ]% S0 Q
sel = new Selector(obj.getClass(), method, false);
% R5 l5 F2 S x } catch (Exception e) {/ R& l! {! u( j, a2 l) E# s" m
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# i" d5 {3 |+ U/ K: e ~* R
+ (obj.getClass()).getName() + ".");1 V4 Z" S0 A' r$ K; ]) O
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
. L5 g3 u. \9 P# ^$ X# x5 y System.err.println("The process will be terminated.");, s. v6 x! L* w6 z/ d% B0 w! P
System.exit(1);& P2 h3 C$ F$ \ O! c0 ?% B3 |
return null;
4 [- L6 T2 u5 _6 w) K; a9 s }
6 Z- a/ r& ~% ~; { l6 X3 e return sel;
- j/ p* m# H( Q5 m6 e4 ^ }
8 G& l3 F% v5 f/ m} |