import swarm.Selector;) S8 m% y7 r2 D$ H- D, g5 y. b0 v
6 E! I5 v. T8 F" `+ s2 z
public class SwarmUtils {
, `0 m( }/ W7 }* m- t* E5 A public static Selector getSelector(String name, String method) {
6 Y6 e% Q! v. x/ r6 U" M2 X, q Selector sel;
4 [) W* k8 l$ Z. w) | try {- [5 A7 ~+ g1 Z* K
sel = new Selector(Class.forName(name), method, false);
7 D! ^! V3 H2 ]8 O; B } catch (Exception e) {/ t6 z. ?* F1 }+ f& C1 y- \2 v
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- W) X- B$ O) v9 I/ T ]
System.err.println(name + "." + method + " returns " + e.getMessage());
3 L- i7 {1 T) V, Y$ B- B w& s3 d System.err.println("The process will be terminated.");6 x6 x. h7 R. N. W9 K# G ?
System.exit(1);
* j4 I- R$ X, H) V5 W0 J, p return null;
4 Q% _- v$ x. u9 C! L }
' V3 p2 o" V& z9 e; l8 `+ Q: w- r return sel;: {7 @7 D8 I4 I# ]: n: b/ ]
}
3 J2 W5 Z2 ~5 {+ z/ h( b( {/ q- b1 l
public static Selector getSelector(Object obj, String method) {
" |' I5 P U& M( y1 e1 w2 W Selector sel;2 s8 e( K5 q% I6 {4 k3 i
try {! m: \& E% s2 {& A$ r L
sel = new Selector(obj.getClass(), method, false);2 o: L& `& {1 Q. I
} catch (Exception e) {
" `' C+ E% @" f1 |" ]- H System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% |$ _ R$ p* }: K' @. Q8 ^) x
+ (obj.getClass()).getName() + ".");
9 |# b0 x5 t; `; a7 t8 e+ p System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 c+ Q' l- a0 }- D) f! a7 H System.err.println("The process will be terminated.");# R# P0 q7 L8 ~: ?
System.exit(1);* c8 w; X z6 |* d' e2 F- \, b
return null;( ~0 m5 ~& i, n+ Z: a o
}
) g: E6 K6 b5 m return sel;
2 L9 u+ V, x, i' L }
* T3 Q% S3 T1 B* p} |