import swarm.Selector;
& w4 \7 q0 t4 s; Y7 R) @* K" u* O$ F: c6 @; w+ P
public class SwarmUtils {6 a1 n7 d; ^+ Q* q& j9 h+ U6 q
public static Selector getSelector(String name, String method) {
8 v+ Y# m# q/ K$ b4 r Selector sel;" w, L. ~! {, K' t1 B0 P" l" `, F5 ?
try {
8 z; N j2 H. ~$ @ sel = new Selector(Class.forName(name), method, false);& a% m4 T$ L6 K% L. p
} catch (Exception e) {
: f9 I6 s' A+ _, ^6 E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ Z+ m& D4 w+ E, `7 ?. h6 C
System.err.println(name + "." + method + " returns " + e.getMessage());8 `% c. Q3 ~7 Z5 s; P0 A
System.err.println("The process will be terminated.");9 P; r, {. t& Z$ A
System.exit(1);2 V, Z' i$ n4 ?3 @
return null;4 E; i- d( ?/ {6 W- w; z# ?
}' W E* W. ]: I) K4 m3 s1 ~
return sel;
7 y( L: e1 F, |) z6 ^ }
' c/ L2 H0 @. k: p, Q# E1 v7 I6 |2 l6 _4 @2 P3 H. y0 ^
public static Selector getSelector(Object obj, String method) {
6 x4 j* y$ f ` Selector sel;
0 p! L1 v) M6 |# o/ X% @ try {
0 M; h ^) ?, l* @2 V sel = new Selector(obj.getClass(), method, false);$ ~+ p2 k5 m! @- h- p
} catch (Exception e) {
! y; O$ S, q7 e. e: U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 Y x* T* X! d3 q9 i; O) D7 U ~
+ (obj.getClass()).getName() + ".");( K' u$ A' D2 x
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% K/ M" I& F( ]9 N4 t: `
System.err.println("The process will be terminated.");- x5 h5 @! |9 s% ]$ v6 W3 Q
System.exit(1);
1 w3 i( B6 |2 _; M' B% U9 D3 ^3 v return null;
4 S! g# c# C; A r- f4 d }6 [# V0 Z5 k/ T
return sel;/ I+ S) \- a1 q0 h, G0 ~$ P# G
}
* h O4 [- I' [4 v+ J+ y) v} |