import swarm.Selector;
- |! E4 L. R# f% S7 R. B$ Y+ l: o, {) ~- c+ I! n
public class SwarmUtils {
$ U% h; m1 e* [4 V* Y1 f public static Selector getSelector(String name, String method) {
m# u% G1 Z3 e2 h' G: w5 f* E; X Selector sel;
2 N+ G" V1 h) f0 E5 O% W) w try {0 b7 h! w, }4 n5 ^' \2 M g
sel = new Selector(Class.forName(name), method, false);
3 ?3 r( Q1 q6 ` } catch (Exception e) {) F' P: C2 h3 X7 v9 q# W3 C; G/ F& [
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ o$ T4 ~. P1 C/ u# N) W* K
System.err.println(name + "." + method + " returns " + e.getMessage());% n3 {' ?6 K' j
System.err.println("The process will be terminated.");; L, e# ~ X: z; H
System.exit(1);/ \% G8 U& K5 n
return null;
6 {; i4 e/ d9 r) k7 h }- K: o9 h* X' {8 C* c- _* H' P
return sel;/ W U# W2 o9 h7 U5 ~
}* G- R! b0 w& I/ N
; x! T" p5 ~# `: T' Q# P
public static Selector getSelector(Object obj, String method) {
" K5 w7 D7 Y x) W# F: X Selector sel;% |/ Z# z1 j, I. n
try {% x2 n5 H( ?" u+ k3 V! e' i
sel = new Selector(obj.getClass(), method, false);- O( t: _+ Q$ Z9 \. h' X' _
} catch (Exception e) {* l, y" o' V& U* G, e$ e: C
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 p2 P# j8 T) U( k: B' y + (obj.getClass()).getName() + ".");3 B) T: c s5 i% H- m- K6 a0 Y
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! t, c% u+ a9 G3 K7 p2 p3 N
System.err.println("The process will be terminated.");
! _: {+ R+ d9 d8 M) y System.exit(1);
4 s$ Q4 x1 P; [* H$ V; {! f4 D8 g return null; M, _) Q3 S2 k, y3 ?. N6 m$ T
}
7 c7 W) I4 h3 v* w [* u7 Q n return sel;; j* w* P3 L$ n$ S5 U
}
; s U5 g& L" o/ T6 T9 ~, C2 }} |