import swarm.Selector;
+ X# a% p* G( y \/ s( U8 K# Y3 _- P: W0 C z
public class SwarmUtils {
- U2 ~& K, \# e7 k* u public static Selector getSelector(String name, String method) {6 K/ u# T9 v# D
Selector sel;
% n( c1 v. P Y, U7 d/ E: L try {
( F. ], D7 Z4 z2 b4 j sel = new Selector(Class.forName(name), method, false);- @* B" n6 C1 O$ f2 V! Z9 z) u
} catch (Exception e) {
3 Q' |/ }8 [9 v9 _! e+ @ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
/ h; Q+ `5 Y, x# ?+ g- d System.err.println(name + "." + method + " returns " + e.getMessage());
; J7 F" Q( h$ q n System.err.println("The process will be terminated.");
" S& E3 N3 Y' ? System.exit(1);* u, E8 y e. { X5 ~
return null;8 r6 w: L! b! k* k
}
2 w4 O, \0 J8 w1 [$ l* v return sel;, [+ v W- e& k7 a4 K
}2 s! `) V( p! l* s* ?. h. B( H
2 c7 i$ y/ e f9 z0 v
public static Selector getSelector(Object obj, String method) {
- R8 e& a7 I8 ` P Selector sel;
/ k2 O9 ]) ]4 q0 c; ~: O5 l% ` try {6 G) | Q- z2 t! p" l( r6 Z
sel = new Selector(obj.getClass(), method, false);+ y) s/ d8 }5 c* z" X) K
} catch (Exception e) {* ?$ C s9 q6 A* U8 I
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! z# r) `+ z& L% N' B S' y + (obj.getClass()).getName() + ".");
8 s( ^% Q: o# L# T" P System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 M: T: e' h- e
System.err.println("The process will be terminated.");
( V" O/ ~ @& F# ? System.exit(1);
% S, X+ r# A) }* e! x return null;7 ~9 M5 l7 T6 N7 a1 a5 T
}" { Q6 i; x5 b& n
return sel;
7 n& l+ I( K" u' |# P9 ? }' Z4 t4 W; l* G0 |. S! K5 l
} |