import swarm.Selector;* q% `8 l8 ?/ X3 ~
5 q3 z2 [8 ]( X" [! v2 Ipublic class SwarmUtils {
) I! Z/ _; S6 Y9 `) M public static Selector getSelector(String name, String method) {
0 v* X$ w. [, J7 R% {5 E" n Selector sel;( M6 U4 v$ m% m2 u
try {' B0 N" [: d# t0 [3 X0 Y
sel = new Selector(Class.forName(name), method, false);
: n6 w+ B" P* f3 A+ Q9 Q } catch (Exception e) {0 Q3 i* X" j" R, @# J. S
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 x: j2 a% b: Y4 q8 h. s: T3 V P4 }/ E
System.err.println(name + "." + method + " returns " + e.getMessage());+ H9 M( @. A2 o* K9 q# @
System.err.println("The process will be terminated.");& w7 }$ T* M. I$ L5 i/ r
System.exit(1);
. H: @, k; b l7 C return null;
& t3 v( m- ~( b" Q$ G6 Z0 f }! K$ P, Q+ v& h4 M9 V1 ~% k+ ^
return sel;. r6 r5 `. B' k5 i
}
4 S3 t8 `% z# i5 B
* {. ]3 I4 q6 R2 G% d( o% b. s9 d public static Selector getSelector(Object obj, String method) {1 u' v& C( J9 {4 J; v/ |. C
Selector sel;2 x+ v" p: K7 M
try {
" I* @9 N- @5 o sel = new Selector(obj.getClass(), method, false);
- t# }- N" S d5 A } catch (Exception e) {, C% w: n% Y5 A$ z7 s
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ U5 l( a7 {; [% t1 G + (obj.getClass()).getName() + "."); |- F/ X, ?# J
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# s5 j$ U7 p+ a' b5 j% ]
System.err.println("The process will be terminated.");
, J/ Z" w/ Q( T" G- A- y System.exit(1);1 ]/ h! R0 v7 h% i
return null;8 A* V; h& k0 f8 M0 z. ?; F
}
% `) \: H' y% E return sel;) ?0 G3 H( h7 }, b' K$ z5 X
}2 B- U, u' @- j! `: |
} |