import swarm.Selector;
9 W* S! k J: E. M; J3 `# X& F$ L2 b/ s( Q
public class SwarmUtils {
& j& Q% S( f8 |2 Y public static Selector getSelector(String name, String method) {
$ k& S* p5 ~( o* W% K' u! I Selector sel;
z# z9 D/ _0 T( y, t( Z try {
# o0 [1 X/ N$ e% a& x sel = new Selector(Class.forName(name), method, false);! P% W# ?3 ?) l; T5 N% c
} catch (Exception e) {1 M8 Y: |$ L' I4 H# L! M: i
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");$ P. B: Q3 ?. Z
System.err.println(name + "." + method + " returns " + e.getMessage());% ~" C* ^) r) I" R& ]
System.err.println("The process will be terminated.");
% j- Q; ^; l7 P4 Q System.exit(1);
: [3 O, x9 C& i4 B- C1 H( Y return null;
2 U& E: D( _4 `, | }
) I0 K+ s6 `/ F5 L& V return sel;
: g4 Z8 L4 X0 B) V ]8 {' r" E4 n }
3 Q: Q3 @8 E6 B5 W+ u% b; ^4 N5 O* e( g
public static Selector getSelector(Object obj, String method) {8 m: }8 `" L4 ]
Selector sel;2 e* O4 j$ v ^" C, r+ y3 w" z
try {, Q8 D- R" s- m4 h- k2 B5 g1 ~
sel = new Selector(obj.getClass(), method, false);
8 L4 W$ Q8 t/ C& O. x- P } catch (Exception e) {! w( i1 q" P( ^0 L# u; u) p# a
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "6 T, a+ c5 E1 Q: G2 a( P
+ (obj.getClass()).getName() + ".");6 p7 A! q9 W% ~: P& G6 t6 A
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
. O* G' d% Q6 v( l: l; v9 p0 R System.err.println("The process will be terminated.");
5 [' ]0 O$ Y% S3 Z7 r System.exit(1);. H4 u, U- Y1 O6 g$ L, l
return null;
* {/ ~% |7 e H: `6 Z3 ~; e0 q9 c! N }+ p& w- d2 `5 _7 B; D
return sel;
8 I8 F3 W& \4 f6 ? }+ q) c4 I* D5 _: ]
} |