import swarm.Selector;. w4 G: G7 p: n# y: t Y
! B" {# O: w$ d0 x% X/ L
public class SwarmUtils {
8 i) u K; ?- ^9 E7 \! n public static Selector getSelector(String name, String method) {+ E# }) Y. q8 H. \$ ^ T# B3 A$ K. q
Selector sel;
' q1 p! \& e7 k3 m try {5 O* F: y; c( L2 O
sel = new Selector(Class.forName(name), method, false);
& @3 Q* C0 X3 P+ O | } catch (Exception e) {, s9 `% N. Y! a" F
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 R& o: X3 ^4 P( S
System.err.println(name + "." + method + " returns " + e.getMessage());
" j* b9 U; g* A System.err.println("The process will be terminated.");
/ u( h: i. q2 t6 F3 c; j3 l4 L0 L System.exit(1);
' D# x: S7 l% [ s; N7 q4 X1 w return null;
" o1 {, I% y0 b" o. f }
A6 L: B$ o# I2 x6 I/ c0 j" ~' B return sel;
$ V! T& J h" ?5 n* ^" ~ }
# K ^: Y6 I5 O! `) E
$ N" o- P. v' h! d/ Y7 F5 x! p public static Selector getSelector(Object obj, String method) {
, g# k j* F1 g Selector sel;
6 J1 Y' \. Q& t3 \' H3 ^& T H try {7 n- r# r7 ]' v8 ^0 n
sel = new Selector(obj.getClass(), method, false);
( ^' l, L5 g# q7 g } catch (Exception e) {
y( ~3 z+ w" z. D J+ V" P System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: F3 j d) x u+ i$ i, t + (obj.getClass()).getName() + ".");3 v: S7 R7 C- B }
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( k* Q. T4 c% S6 A: H System.err.println("The process will be terminated.");
# y( P2 y: K1 P8 E$ i4 Q3 Q System.exit(1);
" w1 u5 Y( h+ o. w& U( J return null;0 }/ }2 a) {; G- T
}1 Q5 H5 K2 t5 |. @8 D$ W( L
return sel;
9 q2 d) Z6 f; m4 n* R7 s }
^3 g% O- j% M$ \} |