import swarm.Selector;) R0 Z9 p$ j5 d$ k' R
$ [+ [- v% Z# q' [# |/ \public class SwarmUtils {/ r( Q) C( G6 F" S4 u. v" k
public static Selector getSelector(String name, String method) {
) `8 V7 d: m! \% z Selector sel;% L9 F- n9 z$ S6 w/ ~4 U) p
try {
7 ]+ t& B& Y: N' G, ` sel = new Selector(Class.forName(name), method, false);' E2 D6 @9 V( H1 ~0 }% P0 [. C# A
} catch (Exception e) {
+ i* a+ d3 Y. w/ b System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 ?$ q% \; ]# P# s4 W0 h
System.err.println(name + "." + method + " returns " + e.getMessage());
3 ~" h! x4 W" ?3 y m$ o System.err.println("The process will be terminated.");3 X- Y8 i* b/ E4 K
System.exit(1);! X$ W9 }1 @" F& Q: C
return null;
. c% u. N8 f$ j+ `( Z; M# J }( A4 \- B% ]( ?
return sel;
: ~: ~% d m$ }' U g1 ^ }
6 s v; U; P$ j4 A" t$ o* D
9 k% }- t0 X7 |5 J0 O; a0 m, t; Q public static Selector getSelector(Object obj, String method) {
9 ?' l; P1 ~5 b% H: g& a Selector sel;& O. P" n4 W5 i6 `
try {! n- N$ v+ I8 Y! U4 d
sel = new Selector(obj.getClass(), method, false);
1 A6 m! {/ e0 k- e4 w } catch (Exception e) {; {$ s, H; o" \" E9 d
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 ~/ R/ P& V" i) k3 p& T+ X& N2 F + (obj.getClass()).getName() + ".");; E" [$ @; L- c& ~/ [; Z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* Z" s1 \/ i z! i System.err.println("The process will be terminated.");
8 K# \5 w- N. A' R System.exit(1);
9 z/ F9 @) D/ M return null;1 T$ L" x0 u) L- D, _9 v3 a; s
}5 u/ u+ N" {) f0 }
return sel;% {4 r; i* T! u/ s; i5 F
}- ]9 N6 W$ q; @" v+ J$ H. N6 z
} |