import swarm.Selector;
% P- a& \) `2 Z o3 b" y, d2 e9 {: j, Y9 M: a$ Q. i0 y
public class SwarmUtils {" y5 }8 X! {9 f% N& @; k M: U
public static Selector getSelector(String name, String method) {# k7 R9 a( n3 B6 T
Selector sel;
/ U& v3 y) C6 p4 `6 A try {* K. S- O* y o- P. G& x s$ ]: r
sel = new Selector(Class.forName(name), method, false);
' @' p4 p. P; I1 U } catch (Exception e) {
7 B( K9 T$ \1 @/ d! C( Q7 i0 ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");# i2 G( j9 f2 |9 \& q
System.err.println(name + "." + method + " returns " + e.getMessage());
0 t$ c+ b+ j k P" s' Q System.err.println("The process will be terminated.");7 w& U- G/ k. J7 V1 ?
System.exit(1);
- ?. Q8 J6 ? m return null;, T2 x3 y& a {. C, B$ d9 U
}( |5 \3 D" s$ T' o/ x
return sel;
% u, W* I* E3 i% R3 M" s+ l7 ? }4 c( c! _5 `9 [& m
5 o8 i7 m, A. S# [! ] public static Selector getSelector(Object obj, String method) {# j3 b4 s9 W, W# [
Selector sel;. F7 g. ` j$ _+ r. N& I- g
try {
/ x& d5 w# a& q8 p# q sel = new Selector(obj.getClass(), method, false);
( P! `( I9 ~2 z* Y" t# X; Y } catch (Exception e) {: N0 W& h5 W; x. c7 _
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- J4 \& {) }: d. D; t( m6 ~8 G + (obj.getClass()).getName() + ".");6 N# D4 ]$ f1 S7 Z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" W5 k3 v+ `+ O6 x- [0 a( b
System.err.println("The process will be terminated.");
. Y! r2 F* |) _1 D) k. }7 r System.exit(1);
2 f2 w! p0 H" w# s: y3 O return null;
8 w0 L, t' \7 K! V" p0 @ }
, m% z4 V/ p3 D. K2 R/ G return sel;
' y: ^ X8 M9 A4 [9 r$ U: n7 x }
; ]/ O* R8 h! e4 E |9 m5 x; j} |