import swarm.Selector;% A, A) v: [! k& ^
9 y7 J: ^3 `# a& h1 I0 ^0 z1 `& Tpublic class SwarmUtils {+ O9 a% [. ?' t8 B! ~, \
public static Selector getSelector(String name, String method) {3 F! T% A' u6 ]: A: M) _6 B# R( [
Selector sel;1 U. U) B. P- X: x" w
try {! ]8 s- P6 V6 s* R! ~# e, R# d
sel = new Selector(Class.forName(name), method, false);
5 ]5 w" }: E( h$ m } catch (Exception e) {0 l$ t9 |7 g! `" t( Z3 J) J% z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; l$ |& J5 k; O! c9 i+ C6 P9 S5 n System.err.println(name + "." + method + " returns " + e.getMessage());9 F9 \; j9 }9 @2 b. [
System.err.println("The process will be terminated.");" z. \0 }4 ~. e+ Y% x8 e4 e
System.exit(1);+ I) Z" a! X( |5 B1 R( l
return null;0 J$ `5 R& H" E$ Y' r" A
}
1 B: J* g% |& c" k return sel;" h1 c5 G& i1 C2 ^' G( p" M
}
! G! R) z& t# u# h& `7 ?5 a- ?* ]. x: X* M/ q( @7 I
public static Selector getSelector(Object obj, String method) {+ n) b0 [" n; ~
Selector sel;
, W6 L6 R, a2 w2 N) `1 T% U2 Z try {
% Z# W# x0 J" X sel = new Selector(obj.getClass(), method, false);3 {& F/ v8 A% n2 u
} catch (Exception e) {
+ d4 S) j* y& X System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "- E2 l. w4 `7 I& f0 R
+ (obj.getClass()).getName() + ".");
$ u( `& ~$ X, c System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' O" c1 }: W+ g; F6 @2 o/ q
System.err.println("The process will be terminated.");
B* X6 U7 w0 i) K$ b3 H System.exit(1);
! q. Y1 r8 R) Q% t) { return null;
4 [) p1 ~ m( K A; @" D }
$ H! |- Q; l. w" D B5 Z+ g return sel;
6 ]! e% u" M& i! R1 \( o' q8 R1 }1 }6 k }$ i8 W- c( ^: G L C1 i
} |