import swarm.Selector;
& H1 ?4 e( B% b1 m6 c* Q# H; `( z- |
public class SwarmUtils {: w Z1 {( `+ w f, w: S
public static Selector getSelector(String name, String method) {
% u+ C. t% X3 S; O) t4 }4 Y( K Selector sel;, ^& f' E. C) v- H
try {; O: H( Z" f+ ` P1 m. \
sel = new Selector(Class.forName(name), method, false);' y6 i! Z! X5 s- O# W
} catch (Exception e) {
1 E& Q2 u+ e) v System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");' }1 r3 z0 q; ?$ o7 W- w( _8 C8 U9 |
System.err.println(name + "." + method + " returns " + e.getMessage());7 I% v9 N! {: k, m% {# j
System.err.println("The process will be terminated.");% I5 [$ v& N/ V& U0 c" L- z
System.exit(1);
7 p+ d7 R& [7 d! a ~5 u& V0 A4 S return null;/ S7 a* B* A( x% @. \
}
( \8 b5 Z, H# r- c return sel;" f2 R1 H X( T
}2 |* W) N4 |0 f6 U* w( x
0 s/ A. L/ ^' x7 W4 U9 J( b M& @% ^ public static Selector getSelector(Object obj, String method) {! i6 t7 @# e Q' _4 j6 O* ?
Selector sel;
" T& y1 y- C& u1 Y5 X try {9 S, k7 R! t% H. h: W8 c2 S
sel = new Selector(obj.getClass(), method, false);
; d3 G8 M( }3 _6 J } catch (Exception e) {
" I+ h- E' l. m/ u' O6 u! ?) { System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 w6 M( a& k9 T. f# _: `1 C: H + (obj.getClass()).getName() + ".");
t( P' |8 G' c d' Z' G. B' k, ]& J System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());4 p- R& s& b/ i& A m! m2 C
System.err.println("The process will be terminated.");
$ H" V# `2 ?# q) _3 G. e System.exit(1);
5 s! V! R+ A. ~- z return null;
0 x& I* V, s. ~5 g }: z E. N1 `0 u7 z1 c2 d+ a
return sel;
4 b1 d, n" i6 b }
3 E1 K H5 ~2 e5 N" _7 \} |