import swarm.Selector;# k8 Z3 r% z/ J( _% g6 _1 K
6 m0 @0 V7 {6 J5 ]8 Y: Jpublic class SwarmUtils {
4 N5 N" K, b- s" e& e$ i" q# o public static Selector getSelector(String name, String method) {
8 o3 S1 e5 E: }( S Selector sel;! i" n3 [. D- J) G. B; i
try {8 |7 p4 p# i$ G p3 T
sel = new Selector(Class.forName(name), method, false);
5 i# O6 g% N3 {+ b: a) U4 h } catch (Exception e) {) d" X! ~. v. ?' [
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' c* Y6 x; B7 x1 Q: U& g1 O System.err.println(name + "." + method + " returns " + e.getMessage());( G( g2 n* D- }6 _) G0 O7 U
System.err.println("The process will be terminated.");4 A3 }8 @+ p% g6 P# l
System.exit(1);3 x" b0 X: W5 d3 r
return null;
% ~# ]; t& s4 d; Z }- J" c' e" q: H0 z# J, r
return sel;
4 L. A" ]# n0 E; s# C0 j }
; x' U& E. ?9 |0 C9 ?/ |+ s; R' p8 `
public static Selector getSelector(Object obj, String method) {; z9 d0 ~8 e. s& O5 O8 N8 @
Selector sel;
- _+ b8 J: b# ^7 E! Y9 ? try {9 ]! K' e) w" s/ ^
sel = new Selector(obj.getClass(), method, false);
; X8 Y! E5 @0 I } catch (Exception e) {
6 V) S& @- H) u3 p0 r System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "7 m- h4 y1 k( f G& _) w+ b6 I
+ (obj.getClass()).getName() + ".");
# f& z" ]+ M. C; u' \/ ] System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 F5 t3 x/ Z$ h' f System.err.println("The process will be terminated.");
l& h/ @/ o, b: {! m" F: Z' X6 u& p System.exit(1);
6 O. Q, ^1 d7 r- W2 [! h: H return null;
% a j4 I( D4 c }
# u( L+ \2 [$ ]7 L7 _( w1 {. i. ? return sel;
" A. O( i. @- H, o1 z }/ i4 J$ C3 E7 F `' ~5 O) P" s
} |