import swarm.Selector;& K! Q8 P8 p$ G5 i7 @ B
2 F) x0 c$ }5 Vpublic class SwarmUtils {/ W2 F# T" L% d
public static Selector getSelector(String name, String method) {
, p* B* k' o; L5 n+ ~, J Selector sel;
& _2 l! `+ o% f' F) o try {
3 ?, q, I/ i. P! f sel = new Selector(Class.forName(name), method, false);
# M2 O, r, x" d; f) Q } catch (Exception e) {
3 J: I4 |5 F. H/ C5 C" Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. r; _$ X( q; H System.err.println(name + "." + method + " returns " + e.getMessage());
9 E5 E8 ^( s9 W! \; b3 v, g( u1 O System.err.println("The process will be terminated.");
* v# m0 ~4 R+ L: F) d9 V5 [, k3 } System.exit(1);
% X* ^3 Q* ^0 K2 A) _" M return null;
- U; j# A( d; P) B; i3 j* G+ e, h' S }& w% m* \& E! G9 f
return sel;. S4 ~; n- O' z' \/ i. U, Z; R
}
2 W) [4 O2 t6 n& Y1 c5 O' E2 T' [5 X( w* G! L/ ~8 c
public static Selector getSelector(Object obj, String method) {3 Q+ p% A# {$ X9 W% g# z
Selector sel;
% s4 b' ?. C! e/ a7 B+ ^& s: @" d$ T A try {
7 e9 y+ X; D6 ^* x sel = new Selector(obj.getClass(), method, false);
V& D( F4 j4 m7 O0 Q } catch (Exception e) {, l' m# e+ c* m F# d2 s( J5 X
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" K) A3 c% r. l" a: ? + (obj.getClass()).getName() + ".");0 o( g/ n. Q% g3 f
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); D G2 e$ r1 w$ `. N# r
System.err.println("The process will be terminated."); b( u. [" p: ]) Q0 P9 q: Z
System.exit(1);+ L, v# W& k q" R
return null;
7 ~. R: p) W. ^ }5 x2 y* w) n8 W" k1 |
return sel;
( P3 U; r. j! U- V) c! | }: d% J' l& Z0 v9 m: J4 s& k
} |