import swarm.Selector;
! w2 j' t% O( c' ^4 s3 _8 \9 U. c- S
public class SwarmUtils {
0 E* R. b7 g8 e4 u1 b public static Selector getSelector(String name, String method) {
8 ]+ N3 _/ i- m) W; w! F6 H Selector sel;) f. I/ \2 u/ {: ~
try {# Q+ {, g5 V& g* f
sel = new Selector(Class.forName(name), method, false);
$ x/ P4 q/ Y; M3 I; \3 H/ N) Z } catch (Exception e) {0 A/ G- U2 O. _, Y
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
2 P6 ~% S/ M6 I' Y0 p System.err.println(name + "." + method + " returns " + e.getMessage());
2 v" D7 e! f7 i; P% e System.err.println("The process will be terminated.");. V6 g4 \6 \) j& I1 i4 X
System.exit(1);
/ [0 B' D( h4 }8 c7 v0 a return null; e, f9 N8 s4 C- T( Y2 d1 U8 i' k* {! A
}( R2 ?2 J0 j3 @
return sel;
' a4 D9 ]: |, k5 F9 I: ^" q }! U8 B O: @, p* v+ S0 ?
& \. n w" W5 X* v public static Selector getSelector(Object obj, String method) {
* ^" Y% n1 U+ \ {' l! Z Selector sel;/ q& r% U% x* r" B, ?1 _
try {
# L1 o. C! S* A5 D0 K2 Z: x K sel = new Selector(obj.getClass(), method, false);
& m7 O7 {! V, K( |+ x } catch (Exception e) {6 f1 N2 `: E6 @
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! n& ?8 g' P8 C5 G4 _8 } + (obj.getClass()).getName() + ".");! x" P( f7 t; c5 \
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());3 [& m6 P& E$ _6 n2 r3 U2 [
System.err.println("The process will be terminated.");
/ ~) U/ H& U2 U' A* ]+ W* X1 m( i System.exit(1);
/ U; ?$ E( s8 D2 r5 D7 Z. |+ y7 r return null;
, N8 [2 F/ k& k# d2 `, | }8 o' v4 t6 q5 T! k
return sel;
|: r1 @$ i1 v' I }
' v; Z0 @2 z$ o0 n} |