import swarm.Selector;: G5 K: _$ W- F \% m" V
7 r( e. N9 Y, c9 H1 Z# G4 ~
public class SwarmUtils {
R! [* o5 d4 R1 g f% R public static Selector getSelector(String name, String method) {8 s; {: D8 E# R. _
Selector sel;4 l9 N9 J0 m5 h$ N1 Y K
try {; R! Y2 }& C7 P b3 c7 F
sel = new Selector(Class.forName(name), method, false);
* t% J8 q( K6 l; h6 K } catch (Exception e) {
" h) h# i- A* s, S- k: @ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");2 U7 X) z( \5 L5 P, T: U' Z
System.err.println(name + "." + method + " returns " + e.getMessage());8 s, j8 d% v- Q- Q" |
System.err.println("The process will be terminated.");: x' j2 ]( A; g$ i- \- Q, w
System.exit(1);" r5 x2 ] S9 N3 K `# o
return null;. w7 ?: Y0 s+ p7 g# U
}0 l E: E( r4 _' w* Y% [
return sel;
% f( N5 ]5 e7 r }7 H8 P( G2 b; _+ Q* Z) `& U
7 T% \. N% m! d2 q! g- t- B3 ? public static Selector getSelector(Object obj, String method) {
! i: [0 ~) @% l5 l Selector sel;
* q6 q/ g5 @4 L! O try {' d$ W1 q9 n+ a- e) K/ }& b
sel = new Selector(obj.getClass(), method, false);
! M. g& f9 K4 R* x3 U' t" N: G2 x1 s } catch (Exception e) {
0 g0 {. G" f3 f- M6 z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# V q# Y' j T6 d2 _& z7 e( p
+ (obj.getClass()).getName() + ".");2 ]& c2 j/ _/ T5 N& k
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
. K: L9 @- x2 @# o9 P System.err.println("The process will be terminated.");4 c' V$ @) x% A
System.exit(1);
5 A/ ^- A/ t. x( h' F" ` return null;
" _) l: l! d- G6 D5 D( j Z- ^( K }
8 C2 W3 ]1 z$ J/ d! s O3 k/ c& V7 D return sel;5 C. l/ \2 u5 R& A" s. Q
}9 @3 |" R! O6 _$ q; H
} |