import swarm.Selector;% F% J# G, H- W! Z" S( N
+ y; i4 K5 y0 @$ d3 d- V" `) b" Qpublic class SwarmUtils {$ I# z" Z! P& }% X
public static Selector getSelector(String name, String method) {" o/ |& N1 H3 v3 Q* ?
Selector sel;7 B3 @: d9 ^1 T. _
try {# U& z8 n+ k% _/ g4 c
sel = new Selector(Class.forName(name), method, false);0 q0 p4 A, t" Y0 c" s. R2 }7 G
} catch (Exception e) {
* t& w5 t7 i V7 D0 S( B4 ]) A+ E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
3 V N5 b1 |. H+ D System.err.println(name + "." + method + " returns " + e.getMessage());
0 w* z5 Q/ x3 O/ A3 `9 s/ \ System.err.println("The process will be terminated.");9 p: u2 U9 S# q
System.exit(1);
) z, K5 r, |1 \1 F& H2 b, ~ return null;' ~! K2 C* m" |$ n& p* {; K
}8 t# v X2 b' J9 ~
return sel;/ n, ?5 X7 n+ j' Y9 m+ c
}
5 }3 C! n( u" F8 Z) d' F6 J1 {: c( {4 V! B( _* Y2 L: Z4 y. R
public static Selector getSelector(Object obj, String method) {- W$ f. C. }* u4 Z% ?2 n% {; p
Selector sel;
Q( S: ]8 k' G! o/ j/ Z try {; K7 B, P c) s9 d4 Q
sel = new Selector(obj.getClass(), method, false);6 Z* `. G" G& I9 b
} catch (Exception e) {2 m" Y" F: o3 U) y2 u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 q' Y3 i# [) d E' i + (obj.getClass()).getName() + ".");; V+ W$ U* V+ G( s2 o: h! J: w
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 R7 E9 ]/ h6 c. m System.err.println("The process will be terminated.");# F5 w$ V& _& N+ P5 ^2 k/ U$ j& c
System.exit(1);
7 }4 i! {$ s; \, I" V return null;
6 p/ F @2 h, f+ R- Y }9 k) ]$ B) H+ a
return sel;1 j5 [4 W: W, u5 ~
}
' O3 \' v' u+ r. c% ?9 U} |