import swarm.Selector;. k0 m( z& k* ?+ [
1 U! }( b% O. J& c
public class SwarmUtils {' o8 a8 Y+ d! F P+ y. b( j- D
public static Selector getSelector(String name, String method) {
% S# @0 }2 `: v7 w/ b" C Selector sel;$ X( }9 B7 z" ^& F
try {
2 E; M3 Z. @1 Q sel = new Selector(Class.forName(name), method, false);0 N: A4 X- [* L
} catch (Exception e) {. l& U5 {" {8 N5 K# ]- z- z6 L
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" O( C' }2 F& y6 W2 B( v
System.err.println(name + "." + method + " returns " + e.getMessage());
2 X8 Q8 @( l5 K" |& C6 C9 v; J System.err.println("The process will be terminated.");
$ E! K9 F, n& r6 N0 u& Y* ] System.exit(1);
& ]4 A3 \& C/ @; p* i5 @: G) C! _ return null;1 ^9 }$ G9 S' e% n& e$ n
}
0 z0 @. G- C) X3 P* D- k return sel;
6 G6 i. _0 @5 l1 L }" p" d& O4 i8 t$ s& F# Z! \
$ l8 B+ m$ {; z$ x
public static Selector getSelector(Object obj, String method) {
' D( n+ q) l" x Selector sel;( L8 d: _+ z! _& h4 n6 j0 V) x
try {
# F; N; `# J( P: @7 u sel = new Selector(obj.getClass(), method, false);
; `5 q" I; U) ]; I4 { } catch (Exception e) {
7 n! Y' d# ^" D9 z) v3 o System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "- m7 _& \8 K6 s, B }
+ (obj.getClass()).getName() + ".");
7 m! K( Z- O! x& I* g/ {( b System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) @8 a% H9 y; S System.err.println("The process will be terminated.");+ J+ Y ? \6 u; i9 b# Q
System.exit(1);1 i4 y# i% s+ I; [) X) i
return null;
7 U3 [+ F6 s" r9 W }
7 g+ c: J$ C% L; z3 V0 s m7 ~ return sel;3 x* u$ D2 {+ z
}9 [% L% J( }- V& n3 N2 i3 M
} |