import swarm.Selector;! z5 z: X/ Q1 H
b k7 z8 g+ j
public class SwarmUtils {5 E2 N) o: S1 ^2 U! O, ]
public static Selector getSelector(String name, String method) {
( y( h' j; |! q) \: M) i Selector sel;* t9 b% B3 y3 W: P8 p, B9 |
try {
+ |8 A; a) [, K( i t sel = new Selector(Class.forName(name), method, false);
$ ~5 ?- b6 b4 Y0 ` } catch (Exception e) {$ i/ `1 i! @+ C6 R+ V
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' z/ j# S! a+ `4 T( |0 L0 h; c System.err.println(name + "." + method + " returns " + e.getMessage());! X3 ~7 h6 C h6 _" X# r
System.err.println("The process will be terminated.");# \) |6 j7 W; d, A8 |* g3 U
System.exit(1);
- g! y: [) J& x7 I9 X8 |8 l return null;
! L( @" W* d+ H2 W0 |1 q& r! b }
0 w, r/ m8 }3 L; Y3 @( @ return sel;8 ~, k( D% } ]: V: ^
}
! }$ ^7 o0 D2 ^' E6 S' ]
D. x) I; L1 j1 w Q public static Selector getSelector(Object obj, String method) {
' a/ t6 t$ u' E9 q/ [ Selector sel;5 `. d9 U9 y! S. }, A: P
try {3 i! J5 p: m% s4 H. E& |
sel = new Selector(obj.getClass(), method, false);
& ~- b* V2 i2 k% r8 o! E } catch (Exception e) {
4 d+ T$ K/ [6 Q& ?# ]7 I System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 p3 t8 o/ ?# Y+ G + (obj.getClass()).getName() + ".");
' y& ~1 F6 Z: z" @ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) v& T) M0 v9 ?2 E, p0 x1 K& i System.err.println("The process will be terminated.");
& A5 O6 w. s6 A( l System.exit(1);5 U. d! L' D2 M/ D9 p
return null;
) Z4 Q% |+ y# y# c6 Y1 C }4 l' `/ r4 H C4 W. d0 K
return sel;6 K- v' T. H5 ]
}# J, r! i, p. {, H2 k
} |