import swarm.Selector;( _. p4 P- e$ j
, ^4 X( I4 v, @; G6 @* `) i
public class SwarmUtils {% D# w: ^6 z% m5 s& `3 }& z' m* t* I
public static Selector getSelector(String name, String method) {
* i2 i* D& P, B/ M% ]6 m5 R Selector sel;4 M# m; d; A' n* I
try {8 t- z/ E+ L) v# U/ T4 ?" Y$ U
sel = new Selector(Class.forName(name), method, false);
/ F# w$ v' K' z. Q1 G6 R! s8 q- l } catch (Exception e) {# b+ C3 v: ?+ ~' X" L! U8 V6 U) i
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");. v7 E \3 o& N5 Q
System.err.println(name + "." + method + " returns " + e.getMessage());
+ y4 V$ t7 V6 T: s System.err.println("The process will be terminated.");
4 C q8 s8 u% F U# f System.exit(1);
9 ?9 a5 G5 P" I return null;
* y: O3 o: P1 `, D( C }
8 h+ Q3 z9 H9 n! J* \2 W# Z9 Z return sel;
* m7 x$ l: o. H0 c# r+ d9 E% | }# X. V' X4 I. A' K
" h9 ]) y. ^5 I" F. `0 @( ` public static Selector getSelector(Object obj, String method) {: c* U8 ^4 S( }" {( V: t
Selector sel;. p, h" k, x' P: I) p# `) o
try {5 X/ {* Z% F R! w# v$ w5 n( d, G, G- n
sel = new Selector(obj.getClass(), method, false);' ?7 [, ~/ F7 B$ ]
} catch (Exception e) {
3 C% t- L. E8 K5 S. x. t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ `/ Y! [& H0 _/ A, P8 t; D K$ D+ m
+ (obj.getClass()).getName() + ".");
# `0 E A, @1 x( a' \7 B$ P9 p System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" A3 U- c) n5 Y/ z: r
System.err.println("The process will be terminated.");
6 n+ m5 r- z$ y: `, a System.exit(1);
0 j* Z: p0 q7 w return null;6 I- P/ R" [, J& |: W' O3 c7 y
}, j, q) W2 a' y( E9 _
return sel;
N5 B" }) Q, m; Z1 p; r }4 x M+ i5 q7 F
} |