import swarm.Selector;
4 C) O9 c) F* l! t' [
W% K2 I7 D" Opublic class SwarmUtils {4 G3 k9 B* R ~ X% p
public static Selector getSelector(String name, String method) {6 v' a Q: S G
Selector sel;
7 v2 J4 p h, M) z9 } try {5 ?, M% j L* O! a( u5 p+ r' X+ @
sel = new Selector(Class.forName(name), method, false);
# ]& q2 S4 ?9 p7 f7 A- j } catch (Exception e) {. ]- e, I. E- Q' Z1 y3 H
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: _# B5 o) X- _- z
System.err.println(name + "." + method + " returns " + e.getMessage());% D* W( j' o& L. E
System.err.println("The process will be terminated.");( h* }7 ^1 }) d6 U* d( ]6 P
System.exit(1);
; ^; j6 [, \( U5 E# G; _ return null;
& S0 j% G E7 r& N }
* ?% M8 h& P! \/ u7 ` return sel;
( w0 a3 t; A6 @ }
' [3 Z, o' ]) F$ O$ E$ d5 V! G: l7 x$ w
public static Selector getSelector(Object obj, String method) {
0 d- |! Y1 ?: z! F4 n/ ]* V! ]% a Selector sel;
9 x- Q3 E) d3 N, S* x try {
/ D5 L1 {* V% ^0 I& k* l# p sel = new Selector(obj.getClass(), method, false);# [$ C$ M! m9 X# L7 B# Q
} catch (Exception e) {
2 v V+ N+ `# T5 [2 q3 V" g System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 R( ^! U) ~8 A2 w + (obj.getClass()).getName() + ".");
) c. f( m, Y4 A, g4 n2 T! L/ p System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! c+ X# [' Z# O A, y
System.err.println("The process will be terminated.");* K" \' {- a2 U- ]: v* b
System.exit(1);' J. \# k+ y6 F5 m! | J- L7 H
return null;
, S0 h6 a! M: s. ` }
% y. c$ e; h7 v3 E( d V0 r return sel;
8 t d$ Z, r: `, M- h& { }, L8 ^# n9 F% |/ ?$ v
} |