import swarm.Selector;( l' G* m! l$ P$ K
8 w! c( U0 d- n; p e
public class SwarmUtils {* j6 x, k2 B0 J/ E/ `
public static Selector getSelector(String name, String method) {! R* {5 T- X8 |: I: n
Selector sel;
' W( u Z; T9 @8 {& `+ w& }' Q& r try {
3 t2 \. m, p1 K0 K, q- y sel = new Selector(Class.forName(name), method, false);! @3 c& J1 T+ ], _9 u
} catch (Exception e) {# `# n& t7 _1 m- n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* [* s8 D$ z- c* D) c System.err.println(name + "." + method + " returns " + e.getMessage());3 X3 E/ P9 @- ^3 ]% g7 X
System.err.println("The process will be terminated.");* L w' N) L% Y" f+ P* E- q$ j
System.exit(1);$ V% c4 i( Y x; x9 K6 |) I, A& W, n
return null;, N# a) _* L, o
}) @! R( R' c7 C/ R
return sel;
5 j3 w" a/ y) h! u: B: R }" i1 F" G* b2 X1 Q) H
: w8 W" J% o, H2 p2 S public static Selector getSelector(Object obj, String method) {% q: V5 ?" h- z/ ?
Selector sel;
/ B+ x3 G" Z$ `" _" W try {
5 k9 Q- V$ M. \* G Z8 ~ sel = new Selector(obj.getClass(), method, false); z5 ^8 k5 n) |) ^2 [
} catch (Exception e) {
( x+ k5 a8 ~! H, n" S5 I" T System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ". q5 _5 ~. Y1 z0 f
+ (obj.getClass()).getName() + ".");1 m! Z# x4 t& [9 Z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, m P0 [$ C+ K* m System.err.println("The process will be terminated.");4 q: w, W9 W! @, E
System.exit(1);
+ s5 j! J- x, j" }( Z0 ` return null;
0 |+ ]+ _7 \. t' J) d# Q }9 l# P$ |7 {7 X }3 c1 z
return sel;5 Z" o6 E# \; x5 d# {& o0 O3 w
}$ T6 W) v! W9 d L/ ~) }
} |