import swarm.Selector; ]8 P( O- v* }/ I8 U- G: e5 D
/ R8 D7 J& q9 W$ h' b1 S, o# o
public class SwarmUtils {9 q( g; |; Y. I
public static Selector getSelector(String name, String method) {$ z3 d4 ]+ v5 b$ }- Y; }
Selector sel;
% V! X9 R/ V+ }9 }. r try {" w- b' [% i7 t+ G& ?) h
sel = new Selector(Class.forName(name), method, false);( K' I* b9 W# y( F6 A0 f" _
} catch (Exception e) {
7 E6 J- E% T+ e' u2 b System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# ~2 X, F! l2 D System.err.println(name + "." + method + " returns " + e.getMessage());
3 E, G) C1 B, w2 @5 n System.err.println("The process will be terminated.");, |* R9 k; m) m+ R( ?0 [# n* I
System.exit(1);: p! X5 c; R# p6 K# m# ~ i Y
return null;' k9 y+ t7 ]( Q8 _9 C# n
}
. ~' j3 v0 H3 V$ d return sel; K+ C2 \: {/ b) A
}
8 W* H; j9 l5 n+ p- J$ t! [5 a+ ?
public static Selector getSelector(Object obj, String method) {
9 l4 i( K/ t. ?- J9 Q1 o! I4 l Selector sel;# K3 B3 h9 @$ b; W4 N! h
try {3 p/ }! Q) U& t( d+ p0 e8 K: P" N
sel = new Selector(obj.getClass(), method, false);+ W3 U2 j" S) L- P& r
} catch (Exception e) {* O K3 M/ k# d) y0 p0 x# q5 ^: \
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 D2 F8 o7 A, j- w + (obj.getClass()).getName() + ".");% G& V) T: h2 W. [- H: Q
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) G( h5 O- A" P
System.err.println("The process will be terminated.");/ H7 U6 @. T6 L* t1 o
System.exit(1);$ j$ q' {; h9 d! _; `/ U) Q* W
return null;
* Y/ Y) ^$ _1 R; c/ H }( j( q: I4 p5 ?) R3 {; @! E. G# \1 A
return sel;9 {9 T* W$ n2 i, H r' A
}
$ {$ K5 i6 G* ?} |