import swarm.Selector;
4 f7 X# v0 j7 v' o* \6 q+ l Z" v) V5 c2 D0 Y
public class SwarmUtils {9 p& P. Y* y) I7 N I# q
public static Selector getSelector(String name, String method) {- R0 G" d& y1 X* S& z8 [' q1 j! A
Selector sel;/ W5 O: I4 @0 X. M# @6 {
try {2 h% ]8 g. H ?) n
sel = new Selector(Class.forName(name), method, false);
' A$ E# A% Y; @% E' o4 }, z } catch (Exception e) {
0 \. r& R) L8 K+ q$ r0 C& o' L System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 f0 e2 ?0 [( H# q5 s V
System.err.println(name + "." + method + " returns " + e.getMessage());
9 v! Y) [6 N# Y1 W System.err.println("The process will be terminated.");. B4 `9 ^( u* A& V2 \# |5 e
System.exit(1);7 R6 R8 n3 P& I+ h. }! m: ~" E. [4 f
return null;4 ]9 I1 E: i# n x. [
}4 T* c; |2 e& V" R) h V
return sel;
8 J) r, D6 O$ |' \% F: b! E }4 [1 }$ L# u: z6 v) `1 I
6 s& A' G. f/ S public static Selector getSelector(Object obj, String method) {
; m8 u( e0 j1 {. g6 ^. { Selector sel;9 r2 x' C/ d! j/ m0 Y
try {* N7 C# n5 _7 u* k7 @
sel = new Selector(obj.getClass(), method, false);
& G6 E: R$ k8 p! Q% l } catch (Exception e) {* V- }& g* K/ p2 [' M* j, v9 s
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "* T' n! L) U4 I6 [ L
+ (obj.getClass()).getName() + ".");' z2 ]; v% \4 l/ W9 o& p
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% Y- U$ q9 i4 o b" `, W
System.err.println("The process will be terminated.");
, O m+ f0 r, A/ g System.exit(1);) z3 q' x4 I! u& }1 d, F% p- R
return null;
2 c$ `) c" L8 p7 I/ r' C/ J+ q }/ w- N' T" Q& y+ c
return sel;
4 a! P5 l# g" G# V* Z }
: J# ?9 k$ m7 `# I+ ^ s+ C! ?) }" _} |