import swarm.Selector;
i+ f F9 V( A5 m( ]* n
$ b/ z# H5 P; q' H. W0 zpublic class SwarmUtils {3 N1 Z7 M% ^3 Z6 |
public static Selector getSelector(String name, String method) {% ?1 s9 X6 t) N' @/ c
Selector sel;
. {# Z. O% o N _8 d; X3 ? try {/ L) a/ I% H# \* d7 _6 x
sel = new Selector(Class.forName(name), method, false);
' \, V; c2 u0 o. z& x4 t; _/ O } catch (Exception e) {
8 r8 V+ C3 D. {* c7 m. r/ u System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 Z& \2 ?* y' X" \ System.err.println(name + "." + method + " returns " + e.getMessage());
1 a# j2 k2 }1 p; {. [" i+ y& x' y9 r System.err.println("The process will be terminated.");
0 S, g! e' ~+ h( ]7 A! U System.exit(1);
! a3 n8 e& m8 x0 r6 R' Z9 X, b7 p return null;
+ \' w9 S) { C: J+ G# z' O! X }. @5 `1 A& ]8 X' a, f# U$ ?6 X
return sel;
' c8 J4 d8 H- n3 _" U }
& F. J/ M1 o( X& r" J5 Y1 w2 o1 W( f
public static Selector getSelector(Object obj, String method) {
+ m; H0 F2 Q% x# B- Y$ s0 k Selector sel;7 r: P5 n( \1 m) j1 l% R
try {4 H! J p# A1 l5 r
sel = new Selector(obj.getClass(), method, false);
+ u4 A' j, h) t Q" }8 n8 z } catch (Exception e) {
7 R4 H0 k9 `" f% |' N7 h. I System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ `! }1 d( _3 z e! {8 F + (obj.getClass()).getName() + ".");; H- C B' A; [# R4 [: c) B$ t
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! L6 s* S0 r+ ~& a- M
System.err.println("The process will be terminated.");6 X( |9 g/ s& v2 Y5 b n# H
System.exit(1);
+ l8 F/ s, s" r5 T' _ return null;: u( s6 e) {% E
}, U8 e$ U& u# M, ~4 P5 m1 Q, G6 J. j
return sel;( @! @2 W! ^3 b' W; J! B0 x
}
3 @* l L! j* S' D- ]} |