import swarm.Selector; J3 t4 r" B1 G
. Y9 l( N5 f5 R: o1 O3 |5 x G
public class SwarmUtils {
9 G$ o" i: A7 n# w. T6 g/ g! i public static Selector getSelector(String name, String method) {! c0 i* o. x; a2 `
Selector sel;$ c- i% `; }& Z0 g+ _
try {' ?! o' [6 X( A5 _
sel = new Selector(Class.forName(name), method, false);0 J: S9 D( z) q5 N" y
} catch (Exception e) {
; Z! ? N* c8 P- `/ o4 w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");# `+ S! n! X: j5 {6 E8 z
System.err.println(name + "." + method + " returns " + e.getMessage());
9 R) F( u" \. }, K- j) u7 C System.err.println("The process will be terminated.");0 c, g1 s8 P% m0 Q
System.exit(1);
( H9 s7 H5 J* H [ return null;
* k P6 w% t3 j/ \- m }8 D. f C# U$ [( Z/ F0 _/ f- r8 O
return sel;3 z! a: D' J& _. |( L
}# L3 U' w* ? s% Q0 |% U
! V# A' E/ F# y5 x public static Selector getSelector(Object obj, String method) {
9 O4 G! [- N* |5 p0 L Selector sel;
( J+ E) Y. g6 \+ ~; S8 `% Z try {
& @3 A- n0 c' e0 v: N8 z) |1 H sel = new Selector(obj.getClass(), method, false);
; X& \! C* V d9 Z& t* s1 C# e } catch (Exception e) {
" _) O% t6 y4 p+ O System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 ?9 Y; k* @6 @' W4 M
+ (obj.getClass()).getName() + ".");
. W1 a. _ `2 U System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" w+ H$ L' ?5 e+ g: E, i9 D
System.err.println("The process will be terminated.");
; T& G* m8 @0 B C System.exit(1);
. }8 y# @& ~* b- r B7 _) B return null;
9 U* ^4 b3 u0 U' k! V }* ?1 ^. y: A/ G! ~2 M$ r7 D) z5 r" g
return sel;
( u# G1 O4 t! O/ w3 m, a }
2 w [* l/ s. ~7 A O% a( s+ G} |