import swarm.Selector;5 s- m9 h- S7 C [, d. o
) m* t2 u- g8 n; h( V9 fpublic class SwarmUtils {% t. V$ x+ J! z. B X
public static Selector getSelector(String name, String method) {8 b/ t1 N/ a h; [- a, w1 \
Selector sel;0 B+ s. `$ @8 C* V
try {" _0 s& Z7 r( _1 H
sel = new Selector(Class.forName(name), method, false);$ |! C' }+ Y) a+ Q; w8 j
} catch (Exception e) {
4 I% u0 I0 S# @4 l2 a* \2 ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) w. N$ ~" q) r# @- V' i' U; L System.err.println(name + "." + method + " returns " + e.getMessage());* S, W- {% X" g& s
System.err.println("The process will be terminated.");
O/ h! ~$ ^6 Y: o; y) O) Y System.exit(1);, L6 L$ J4 w% l+ a0 N# z
return null;
, f9 z$ X) I6 y0 z }
# b+ W8 Y# A4 z0 w/ R( B" m return sel;$ ]# N$ f/ k0 C9 S/ w6 T0 x$ m b
}- c9 I! w5 Z$ d5 |) i. M- ~' b( }
# ^: t3 z# \, `6 A" K0 y
public static Selector getSelector(Object obj, String method) {
" Q B' a2 L. b, Z: H- O' Y Selector sel;
* i/ t( [3 i% } try {
1 l7 A4 E; v* d/ s# n% l; M sel = new Selector(obj.getClass(), method, false);
+ M7 I& G( v, H0 R# j! p" g } catch (Exception e) {4 q) C6 z# N2 o* K5 w2 a
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: U) l3 C# T: s5 Z8 y2 m+ r + (obj.getClass()).getName() + ".");
7 x7 Z# P2 @9 U |$ R I System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, s( V5 [3 b7 R+ Z, \6 c! Q9 A* ^" D System.err.println("The process will be terminated.");
; S; I1 S7 ^5 c/ u4 ^' d% I System.exit(1);. A$ f$ y' w- X) U, t( w$ W' {! ]
return null;
) y' H4 Q4 U2 [# { }9 U+ V# L% [* S& V# @' A- B1 B
return sel;
8 n" U. T6 N; u t }% C# n* k8 h4 ]( a" g
} |