import swarm.Selector;; }% Y' D# J9 Q: a- Y9 U
: J# e; \" n' H( i' {1 {
public class SwarmUtils {
' B1 P* F. y+ Y7 \ public static Selector getSelector(String name, String method) {
4 B, A9 G: f4 _: U, x Selector sel;
: m9 t5 B$ a0 [ H {, q/ ` try {" ?, C( b! ?5 ~* z* w2 Q" T
sel = new Selector(Class.forName(name), method, false);" m ?" X# q/ ^- h9 M Z O
} catch (Exception e) {
. w8 u0 M5 O: f) r, p System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 I' `/ b; n" Y6 _. b& Y
System.err.println(name + "." + method + " returns " + e.getMessage());
# V0 m9 S: P6 J5 o4 `; c System.err.println("The process will be terminated.");' S! m6 r( \5 ^% y8 L- U
System.exit(1);
: I# Q4 w- }6 Q8 [+ Z7 t: ]. ] return null;) J$ p2 W0 i6 f' _( N/ k
}
1 ?, Y& {7 v/ H4 _7 A return sel;
Z& M1 T, d# ~. a }6 l, E: l- a% D& C" c5 J, ~
, Y" ?- e: L' w. C, z8 ~
public static Selector getSelector(Object obj, String method) {: I( C- r7 { r, A) n- |- P
Selector sel;! J8 k( H% G A: ?% F
try {
, N/ ~' W! v$ Y" F; g# P9 W& s) w% u sel = new Selector(obj.getClass(), method, false);
8 M9 F2 Z& {+ W) b8 f$ z! G* L& u! Q } catch (Exception e) {8 f# u) t3 m, j. B' ?% u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 H# D& G: Y# N* l, {) n3 c1 | + (obj.getClass()).getName() + ".");
- H8 i3 w3 _1 Z: N' k; F& W7 t System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- T3 t. v4 I" ^+ D/ T System.err.println("The process will be terminated.");" Z: A% t: \: ?& X% I
System.exit(1);9 r4 S0 z7 t) t" H, Y
return null; h+ O& ?/ F% t
}
4 E6 V3 ]! J" t; z# } return sel;' i% H8 p* T, x5 M4 A4 B
}
& P7 }* n+ t! d6 A+ m' {} |