import swarm.Selector;) j! {5 D2 C# X7 K
4 ^7 P2 n0 t# P; B3 Wpublic class SwarmUtils {
" T; D' Y# }, x. w public static Selector getSelector(String name, String method) {) B0 ?* e1 V8 K1 [
Selector sel;$ M, _# j- u* f n
try {& V6 o p* c9 G( I" V+ b
sel = new Selector(Class.forName(name), method, false);
7 n) P y2 O" U0 c } catch (Exception e) {# p% h2 z- b8 m7 ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");1 ?9 G! ^# f( g ?. T' N; Y
System.err.println(name + "." + method + " returns " + e.getMessage());
# v! u; J. ]# r* j+ [ System.err.println("The process will be terminated.");/ p) z4 k) O3 y1 m
System.exit(1);
& g4 Q- u0 ?/ i return null;
# r1 w* ^& L [7 J' Z$ h }
& K& Z$ {: k9 _% P" s8 G* r return sel;7 L- |+ ~% A5 y# P6 w0 ^9 M- [5 ~7 V
}
* U: n3 l/ `0 m+ h" U9 z2 p! Y% @: a: R. ]' W7 |
public static Selector getSelector(Object obj, String method) {" t; h# U) B+ b7 e
Selector sel;# k) J2 O: w! u& @4 Y
try {7 h M: ~& v4 ]# I ~8 d% S
sel = new Selector(obj.getClass(), method, false);! s5 @0 x. g" z* w0 l2 S: Y. v: ^
} catch (Exception e) {
8 F2 p$ O$ |. B! q r, U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 F' ?& t! W; ~* e' G + (obj.getClass()).getName() + ".");
' s: {3 m4 \/ P$ U$ D1 s System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 E$ _: _* M; {# ~+ R/ e+ M
System.err.println("The process will be terminated.");
3 }( L& {) p7 \3 S0 t+ U System.exit(1);+ U$ u& V9 i( y. A- u
return null;4 G2 ?/ f8 z9 v& h! ^$ _# g
}
7 ]1 V8 S |9 i8 e; V return sel;
& [( Y' P7 m# @( Q }" N# N7 H4 G0 m! }- Y
} |