import swarm.Selector;
) j5 J y% J5 m' |4 A
& |7 A: ~8 c+ z6 o5 Z# i8 i1 dpublic class SwarmUtils {/ @- g7 z3 k1 k2 W' G, T% D# ^( A
public static Selector getSelector(String name, String method) {& M" g2 M2 O: V$ b
Selector sel;
, s- {. T8 U1 T try {
# J+ r5 @$ r( X, ]; K sel = new Selector(Class.forName(name), method, false);/ l6 ~" R' ?, b0 t; D" k
} catch (Exception e) {: @3 s" m* S( B4 B* |
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 ?/ F0 s. I; H4 m% R1 [9 J5 ?( N System.err.println(name + "." + method + " returns " + e.getMessage());
! u5 y. m! w* ^/ i0 ` System.err.println("The process will be terminated.");( _, T" Q5 @! |
System.exit(1);
# |' @0 ?& d1 s9 d; d- _ return null;
/ P3 P$ S3 D: V4 m }
* T; H2 @/ z6 N$ F+ w+ ]' Y- l return sel;
! ~0 s# k/ A, C% F4 N8 {4 k$ _# h }/ Z4 W! U2 N& ~% l& u8 d& ~7 P
8 B4 S# s% x# ^+ V2 ~- V
public static Selector getSelector(Object obj, String method) {
5 h, G7 v$ b* m% U. A4 K4 f Selector sel;1 y5 q" t q( }; {* }
try {
/ |7 y6 l: o1 g+ ]! X/ p" y sel = new Selector(obj.getClass(), method, false);
+ g6 h& _! }. O5 l, j' e } catch (Exception e) {
t: a9 t4 y, J! J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ e, J. K! h8 P8 ]- D + (obj.getClass()).getName() + ".");6 T: V6 C" H) k4 L* n5 W% u
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
. W2 V" M& I) `3 `1 g" w2 E System.err.println("The process will be terminated.");9 y/ H' J1 W: f9 j9 L B
System.exit(1);2 _7 d* m! g) [' s# q4 Z& b
return null;
9 c% n9 }% ?3 U2 n$ \8 n }
1 c2 |+ q- v; [' U return sel;- t/ M J7 p6 i, j) J; S
}+ y* j' X) V+ w- q% A" T
} |