import swarm.Selector;
7 _& g, e1 Y6 u, k9 n
# \9 D$ R% @3 C1 D1 D# X% apublic class SwarmUtils {3 \8 q! h8 l& g
public static Selector getSelector(String name, String method) {
8 c0 N! l0 D7 Q Selector sel; E! r% O2 j9 b: c; |& f, i ?
try {6 U k# Q$ R; @
sel = new Selector(Class.forName(name), method, false);
. M; z j0 O* \4 u0 s } catch (Exception e) {, z, P1 o/ E& O$ {9 }8 N4 L) Z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& [' Q, P4 A8 W# h% C
System.err.println(name + "." + method + " returns " + e.getMessage());% }/ n$ M3 x. p$ s
System.err.println("The process will be terminated.");
) f8 l9 [, c( E4 b4 ?+ K2 P1 i, Q5 F System.exit(1);
0 H/ [, U; T4 l7 g4 N return null;
/ a5 p- Z( X! g( S. f }
; r7 |3 |- z3 H1 S( s return sel;
8 u; r' Z* e1 ] }% D+ v# G, g( w
9 S6 q* w, e7 p' X. y7 A- V public static Selector getSelector(Object obj, String method) {
' N! ]& z7 y) Y( t7 N8 r- P4 c+ | Selector sel;
* G( h0 ^4 ?* _- c+ U/ y: R3 F try {
; E% g. ?& A0 M sel = new Selector(obj.getClass(), method, false);2 ]1 z* [% ?/ y+ E' `7 N# F( W( H
} catch (Exception e) {, A* @. a! d. {. s1 o
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. s+ z' |1 x1 O + (obj.getClass()).getName() + ".");
! ?" U! D: v, \3 a System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());+ h% K1 f, D+ L. H$ c
System.err.println("The process will be terminated.");7 `+ C# y$ _/ d7 X9 T: O) @" g
System.exit(1);
0 C8 \: z2 V& z3 D4 k return null;
( p% ?8 Y. G' N# f }
7 v* u. y) s! l0 Q8 J5 @ n* S return sel;
% R& T7 k% |) T2 b# ` }3 [' N& _7 k% E3 U9 g
} |