import swarm.Selector;* y) W! D" c# N1 z. P& T
4 Q6 x- k. V3 F. d$ ~1 y. }+ ?
public class SwarmUtils {
/ Q9 g7 H) O. H5 `) S* [ public static Selector getSelector(String name, String method) {# H7 \, k( G, k4 b7 ~( \6 W
Selector sel;
6 s( \: I( v' w2 d7 K: O4 e$ N$ V0 X try {' T" ]) `0 q; d
sel = new Selector(Class.forName(name), method, false);
4 x/ U: ]+ G) t, K- j } catch (Exception e) {
5 K7 r. N( H4 w8 O q0 { System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) N# V& l. Z' b4 x1 v System.err.println(name + "." + method + " returns " + e.getMessage());7 n2 ]& Y/ r! }7 x" T f6 a+ A h
System.err.println("The process will be terminated.");
! s- |$ X8 L! @/ D: r System.exit(1);
( j1 k5 g8 ?+ Q8 Z! @1 p return null;/ ^. A+ v+ k! q. c1 q7 J t; X
}2 W4 u' u: d: S) ]+ L4 O4 i" y
return sel;
6 m! r0 a/ b3 ]; ^0 S) M6 ? c3 \$ D }
+ H- u% C9 J$ N7 e8 l5 L7 D7 ~7 Q! H7 w$ E
public static Selector getSelector(Object obj, String method) {3 F9 P) D0 }1 V
Selector sel;
+ X& |$ A. D1 T: _' ~ try {. L8 ]% e& x- @/ Y. b' }8 z
sel = new Selector(obj.getClass(), method, false);
$ b% Z5 v) L9 j0 E3 `9 J# R } catch (Exception e) {: D2 V/ e# s, L& x0 h8 s$ N
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' u, a% j* h$ q! z" ]8 Z
+ (obj.getClass()).getName() + ".");/ q4 K( g* c2 O) t6 G: N
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 X, L& y3 V7 ^6 o7 ?" T# }( t
System.err.println("The process will be terminated.");
- Z( u8 L9 ~: p- \' r System.exit(1);0 ]- C# d- c6 M" y$ c
return null;
4 V2 J& t5 J+ `2 T2 g# S }; O! R/ ^# e' F$ g; a. o
return sel;9 h$ ~; m# a( Z( u8 Q: w$ z' H
}& q6 b- P0 Q/ A: @6 C
} |