import swarm.Selector;
6 Z0 x( h) K$ V! m7 U; E' S7 y' g2 V$ B0 y
public class SwarmUtils {+ B# x: X) ^8 g7 C, C+ [% z
public static Selector getSelector(String name, String method) {
/ U. {9 }4 f5 U" R Selector sel;
0 W1 H3 e/ S3 O8 i! V* O! Q try {
% w1 i+ T! L) t$ f% e" A3 | sel = new Selector(Class.forName(name), method, false);
. W( G- o; ]) `6 @$ H } catch (Exception e) {
) I+ |7 A' ~0 o System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");2 @! T. s" i% J+ V( B
System.err.println(name + "." + method + " returns " + e.getMessage());
% |" j4 G$ s' c' ^; L% m System.err.println("The process will be terminated.");" L) E. p" g2 \
System.exit(1);
4 Y8 ?& h D0 l" Y' C f return null;
4 s5 |7 T2 S/ v6 ?2 S) b# Q } ^7 `* P+ I' \: K j( j, W
return sel;. G5 {" V- |/ L/ m
}; T2 J' p8 @* ]" g0 O1 M
' u& M6 a2 Q% f- [$ C$ v* P
public static Selector getSelector(Object obj, String method) {/ }. Z# [. z+ h: m! ~% M3 e
Selector sel;, g" q! F9 x2 Z. j5 i3 S. y
try {# @' M7 H8 W8 s+ x. k' r
sel = new Selector(obj.getClass(), method, false);
6 ~- f5 U8 _5 [2 d. x } catch (Exception e) { J ^- ^. O4 @: E: V) j8 Y$ I: O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. J* ?: w. G% W E. [ + (obj.getClass()).getName() + ".");
' l3 g; b2 L$ Q4 x6 O N System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" X5 H2 y7 s2 E- T! U) r
System.err.println("The process will be terminated.");# A6 h/ R5 O$ R$ S* c& X6 j
System.exit(1);
% t3 K( H" Z* L: h1 `8 ^: H J return null;
0 r, r8 e( U" Z$ r7 o }
; l3 ?8 s- J) I; t5 v return sel;' h+ k y9 H' s
}/ ~7 J3 H# j, b/ U! g) P
} |