import swarm.Selector;
& @# `7 W4 b+ t+ @; W# H% \& X2 d/ c- B" _1 I9 ^2 E
public class SwarmUtils {
! r' t" l+ u! X+ m public static Selector getSelector(String name, String method) {
$ `0 K6 O* h5 m Selector sel;
. j w- G3 E2 ?% S% U" e; O& ?# o9 G4 Y try {# K3 E9 g; t1 \% c& ]
sel = new Selector(Class.forName(name), method, false);
G! E, S* p$ E4 [0 S3 E/ z } catch (Exception e) {
. r) w; Y" I2 F1 A+ t- g9 b System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");) `2 ~4 O: [: ?7 r" F, n% \
System.err.println(name + "." + method + " returns " + e.getMessage());
3 k. V$ \3 I: }6 o' m System.err.println("The process will be terminated.");
$ C2 m% K6 @4 u. r System.exit(1);
! f( `4 s* Z. z return null;8 O# z- l; x6 w4 ]+ R6 H
}, C+ A0 W9 \3 M* h- G' U
return sel;
5 B9 t( s0 t& y4 G }
: n, j% g$ Q5 ^' S/ ? Z: v& J$ a) q- C9 q9 `: |5 B: ~ h, I
public static Selector getSelector(Object obj, String method) {- \& }8 ?. r) ]. A/ ]* ?, e0 c
Selector sel;: i2 E; f, P9 {3 @3 w
try {7 q7 t: ?% {- s, d$ R6 j( b( t) e
sel = new Selector(obj.getClass(), method, false);9 t x \0 e( H% @4 }
} catch (Exception e) {
0 a' [9 l2 d G5 h1 k# \' h System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( v4 {" U* _, v: O1 M + (obj.getClass()).getName() + ".");; o1 E0 x4 Y7 a; z0 r9 H; x0 W7 o
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 p, { h4 S& y l9 p2 _1 b
System.err.println("The process will be terminated.");- @- [0 T5 G) D, D7 j
System.exit(1);+ J' v, x6 S/ Z V1 t
return null;
# Q6 g. N; ?5 K/ J5 t }
7 e* r _& T0 ?. s return sel;: N2 ~1 g8 z0 g1 f8 K9 W8 g
}( Q/ e" h O, R5 c$ V
} |