import swarm.Selector;
& o( K# _4 }. P3 T) O8 {6 p: C& Z' {+ L2 U6 s* V
public class SwarmUtils {
9 m) r! V: f! }6 ` public static Selector getSelector(String name, String method) {- u! C0 r" }: D+ g
Selector sel;
0 r' D; j& R5 C7 j( S5 Z3 H# q: ~ try {! `* \2 T8 S1 c( A5 K( q4 a
sel = new Selector(Class.forName(name), method, false);7 S! t( x8 O8 F( P3 z2 B" C. G
} catch (Exception e) {+ U+ X! r6 E" ~4 S2 e) i4 A3 X. l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");2 o9 T, y4 v1 n, K2 m9 ?
System.err.println(name + "." + method + " returns " + e.getMessage());. B5 j, U& x6 F0 e5 E& ?: v
System.err.println("The process will be terminated.");
" q' F7 [1 H# h. I/ f$ S System.exit(1);
& s% y1 h# K- q f% F6 R return null;
! Q- L# E# g0 J, H2 {6 g }
. _; ?3 Z0 z% r; _$ ? return sel;4 Y, Q: n. Q* t& T# y( Q
}
4 x6 n' ` ?- r, C, _8 J* D
7 i2 r& v6 x8 {. b5 K* g public static Selector getSelector(Object obj, String method) { S' @% H9 N3 i2 A* C6 |5 h4 u
Selector sel;: m# S2 {; P5 |; n* ^' E' o! {
try {5 x/ D$ w- Y0 D2 [% \/ k
sel = new Selector(obj.getClass(), method, false);- G5 S, l9 E, x' ?# ?- b0 w$ `
} catch (Exception e) {% T1 g7 a1 R3 U' k
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" Z0 V9 X* Q0 g+ M1 c& Q + (obj.getClass()).getName() + ".");0 E4 @& r# C9 \3 z9 _2 S+ F
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) j3 v+ n% a* c' r' a9 W' P
System.err.println("The process will be terminated.");4 W, O, Y3 g$ F4 {- t- i
System.exit(1);
* X' N2 O: j/ ?# ~/ q9 i4 [ return null;
/ U. b) V8 B& f. L9 b t1 g y }
+ ?- t; w: n f0 `' h return sel;
l/ q! _7 p% {3 r# \ }
5 ^" ]7 m2 ?9 H5 _" i+ O B+ y} |