import swarm.Selector;! H7 b" Q; f. l: m4 n" V! p9 f
1 ^3 K+ P/ e H, x; B/ ppublic class SwarmUtils {& B! N( S0 |0 c2 }) J# a+ m+ c
public static Selector getSelector(String name, String method) {
' T5 P9 d' i6 o$ V& t; D/ g Selector sel;
0 E$ B* a( \! X" O" M try {5 t( F4 c# R& X' D4 n& b
sel = new Selector(Class.forName(name), method, false);
0 Z+ Z# _7 g% O; C( g } catch (Exception e) {
+ v5 k2 O" [3 O+ |9 {) y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");. E1 _9 P9 o& C: Z3 V4 M
System.err.println(name + "." + method + " returns " + e.getMessage());4 W* }5 p6 f& J, W* _# E0 Y
System.err.println("The process will be terminated.");
& I) v, Y! c+ _# l( q" ?! I System.exit(1);
, i! o5 K/ Z5 ~% u- Q return null;
[4 ~6 E0 C6 h! }+ N/ ]0 q }
+ V( v. h- p: c: E, u! @ return sel;$ f# b3 o: ^* B. d! `
}
6 {3 u4 y9 Q7 r: H' s( D% G& |
, K, ~7 m* U0 g; y. V" @ public static Selector getSelector(Object obj, String method) {
( y- [4 i5 `% O& O! u5 a, T0 i: W Selector sel;
" A* B3 F! @/ R try {
7 ?3 R( i8 f5 [' H& m sel = new Selector(obj.getClass(), method, false);7 I- g6 V# x& y6 S. n
} catch (Exception e) {
0 K; u! a* v& \' g, X. ~+ w1 R System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "* U0 h. q- L( V& L' a0 T" d
+ (obj.getClass()).getName() + ".");
: U6 Z& v& @3 b, a3 t System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, Z" Q+ i' z2 i; R; h
System.err.println("The process will be terminated.");
$ j8 Z; A$ u/ t) J) ]7 B System.exit(1);0 [+ x l* r- f& z& O
return null;: H- `; [7 T- n5 a0 P+ i/ U
}
J6 u& v$ P; ]. {# o return sel;0 `" [6 t p @& x% ~+ H
}3 `6 n: s" u) E; `
} |