import swarm.Selector;
% @" l" G5 ~9 r* f! x1 B" M* D) k, \: |) d5 f! c. R2 }5 Z' n8 g& M. c
public class SwarmUtils {
! j$ H# U2 S$ X/ E( F public static Selector getSelector(String name, String method) {
- Z- G2 O3 r$ b4 {& J5 \: N Selector sel;% X0 R3 x: r6 L
try {7 H. L1 l, M7 W8 H! n
sel = new Selector(Class.forName(name), method, false);3 w* S4 n4 N' X" a
} catch (Exception e) {. q9 p5 M/ P4 Y- E' B. g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
2 l1 m- T& H2 v+ @( ~ System.err.println(name + "." + method + " returns " + e.getMessage());
3 F7 e: x' L8 q8 ^+ d2 o System.err.println("The process will be terminated.");
9 l g3 C4 u4 y: M# o& [# M8 e# i System.exit(1);
2 M6 _: X( W* d c$ ], _( x* U return null;
, @. F$ b1 ]* n% B8 X, R) L) \ }
4 @, ~$ ~* ^" c return sel;
$ P2 ~: p. T- Y" N" H5 l y" E) y+ c }
, b8 t# K4 f8 _" O; J2 Q' u
K$ M7 d. B4 R public static Selector getSelector(Object obj, String method) {9 a7 X4 e# `7 W3 F, j" g! Y4 V
Selector sel;
, E# }, U2 d6 `. ? D7 A5 G try {9 q. t# x+ V4 @$ z( U# A7 D+ m& ~
sel = new Selector(obj.getClass(), method, false);7 y$ h1 Q7 F& U8 _* k0 [
} catch (Exception e) {' s( z8 h6 G' o
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! X& C' ]- f6 z1 z + (obj.getClass()).getName() + ".");9 `" Z! d* b. y! q& F
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 U; {3 @. t5 a5 y
System.err.println("The process will be terminated.");0 ^1 d- X/ s M ~
System.exit(1);( K0 Z$ E" a" ]9 L+ b( I0 k
return null;
! }. f: v& D! @( d }: G% B5 |6 P* t& q; [& S) |
return sel;3 F6 [6 U& ~, O! O; b
}
0 O, `1 Q' |0 g8 ] Q. }} |