import swarm.Selector;; ?- S$ g9 u7 j3 {
2 \9 i) E7 u$ n+ B+ w% i$ L
public class SwarmUtils {# K0 r- s" S' V8 T% ?' e7 p* W Q1 o
public static Selector getSelector(String name, String method) {) e1 O9 H2 K/ Y5 n" s
Selector sel;
/ n% Y. p8 _- T# Q% o" @ try {* \1 o0 h8 [1 ]# l# T
sel = new Selector(Class.forName(name), method, false);
% y) Z# |, v4 G' `" T, W; ~ } catch (Exception e) {% M& C: M9 r* l! G; j
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 \9 g: x0 B* O! S5 J: C2 `+ S
System.err.println(name + "." + method + " returns " + e.getMessage());
5 k3 z3 [0 M# q S5 O System.err.println("The process will be terminated.");9 j7 Z# N% ]* j0 Q. y& C$ ]8 X
System.exit(1);" _' }) j0 r$ X
return null;
2 e) X5 X( m$ K- @ }
! |: G+ h- x. @! q( a+ g return sel;& v+ H5 e6 q. ]. M* F9 G% U
}
9 `3 T" g) E$ E1 t& b
8 A. A6 s8 [, { |0 |& F. ? public static Selector getSelector(Object obj, String method) {# O' w# I% x& d6 S/ B, Z! e
Selector sel;- o2 ?: }6 v% H) s8 Y
try {
. l: P7 j4 i" K- C" a, _' R# z sel = new Selector(obj.getClass(), method, false);
6 I' g/ U- v( g } catch (Exception e) {* J4 I+ W! ~5 X3 k7 t7 K8 \1 J
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! t/ b$ T9 Y* `$ _9 i( T
+ (obj.getClass()).getName() + ".");
: `1 G1 X1 Z. r! s! f; [# d System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% H. _0 e3 [" Q# d System.err.println("The process will be terminated.");
: V) `: i1 u7 [7 L* e8 Q System.exit(1);
" O* Y) A0 X6 k3 _( B$ v3 v) J! v9 z return null;
: K. `: `! ~7 z% J7 ^) y* h1 ` }
' M. i9 D3 u4 s, c6 U return sel;. d3 R) f9 [4 c& d1 M! K; s& j
}+ f! e6 N+ a& g* T R: i' |$ w
} |