import swarm.Selector;' ?5 H% k+ x. a2 D8 v R
& h) G/ h% W: ]' W8 [ @2 ~
public class SwarmUtils {
3 D2 S% Z; U" y! H public static Selector getSelector(String name, String method) {
6 `( O* E/ T* [" }6 N7 n Selector sel;0 V: e q/ }. x( n1 x' r* V
try {
5 o" {, {5 W$ p- g6 X1 U/ Q sel = new Selector(Class.forName(name), method, false);+ B4 m% _1 D3 r7 J8 \
} catch (Exception e) {
z2 s' }3 t, n5 Q$ h7 Q; m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ M' K0 k9 n9 Q0 p System.err.println(name + "." + method + " returns " + e.getMessage());
! n p9 G9 i- t) g. ]! E8 o System.err.println("The process will be terminated.");$ x: X+ o5 P1 Q2 V
System.exit(1);
2 V; D/ ~0 [" {9 M4 _5 R- } return null;0 i, u9 g r+ j* ^' [( E
}
@* C" z; u8 ^7 X0 A, Z4 z" S return sel; P" [& E, r- H u `- _
}
! H. J9 {7 {+ U$ ]: P d3 `" ^! c) r: a% O( \' R" w
public static Selector getSelector(Object obj, String method) {5 g& k7 ^, E+ N) z/ |7 ]
Selector sel;6 y1 N4 {3 I# X/ l, r0 ?
try {3 m# h/ I; S- j) \' T
sel = new Selector(obj.getClass(), method, false);
7 F6 m( r" Z' A+ D5 G4 m) G# s } catch (Exception e) {
. ^! O! g: ?6 |9 { System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# [/ H/ a9 u9 C. H + (obj.getClass()).getName() + ".");& d: q; p( _. A! y. J" j+ E2 @# k
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 |) `# J7 j( W- N' C3 ?
System.err.println("The process will be terminated.");
: s6 ?. i8 p8 ^( f( @ System.exit(1);
: B) n9 k; u& [$ g$ c; k3 c* Y return null;4 [. x+ a6 A# \% ?6 `! J
}
: p" H' F2 J) N ?! |% u return sel;5 G* a3 k3 ~' R+ {2 j* Z
}
( V' |5 h C* ?9 ^, h( `6 x} |