import swarm.Selector;
5 ?: D* F4 K+ U0 y3 n/ W' f, D1 n7 C6 s* s
public class SwarmUtils {5 |0 Y( q+ s$ K& e+ _2 k- a& }
public static Selector getSelector(String name, String method) { Z3 r- v1 W% S4 T. \9 ?7 \
Selector sel;) p( ]; b- N* o: }+ v! D. L4 `
try {
: ~+ E1 q$ U8 Q" U4 i sel = new Selector(Class.forName(name), method, false);
7 Y- ^" h$ s( `, ] } catch (Exception e) {* g# D/ N9 ]( {& d- A5 h4 ^
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; D: q/ ?8 X$ e5 x
System.err.println(name + "." + method + " returns " + e.getMessage());
9 n2 O* B4 E" K2 L2 }" ]0 _ System.err.println("The process will be terminated.");
[2 G T7 Y" ~: v0 l' @! Z System.exit(1);
6 t2 L. S& j+ u1 K; C5 j/ k4 w return null;! {3 P1 [# v3 J4 P* U- `+ |
}- X; _$ ]; {# A9 }. ]% }
return sel;
+ q, S3 r9 [" _: G( b7 H# M }, @( K9 R/ c0 g/ J! _% b/ D, {- R
, V, j9 q: J# c# m) }2 o public static Selector getSelector(Object obj, String method) {( t4 x' w R9 v% d7 e4 x
Selector sel;" y8 W$ U8 B. [: u+ U/ R2 S
try {
, v6 c! I# W9 l8 @ sel = new Selector(obj.getClass(), method, false);
, T$ v( V- |% M! \) ~5 | } catch (Exception e) {
9 _0 t' g- ^! Y# a! g' S9 _7 D System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! j: k- H* j/ X0 J' {
+ (obj.getClass()).getName() + ".");
1 ~; Y7 M" Q4 [/ U( K! K5 n System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% {( c% o; Q0 J/ q System.err.println("The process will be terminated.");
2 T/ _5 h8 S: e/ [' b0 i System.exit(1);
7 h9 u& j; K7 X3 s; e return null;
/ Z' K# r% t9 i: n$ y }
9 U$ C2 }9 S! g( a6 C2 ?& E: _ return sel;
3 \9 m K6 q$ `% l) ~0 \* L3 e# h# A }
9 ]7 i- {8 l! k4 ~} |