import swarm.Selector; ]' u( [: [ X5 K
' ?* H& k( E9 T; O
public class SwarmUtils {: x# @# \9 k+ H
public static Selector getSelector(String name, String method) {
, N5 H" ~& M b2 p6 ?4 [9 n Selector sel;6 [: c. a/ h8 J4 y# o
try {
) I( O+ y7 P$ A, A M: t! @ sel = new Selector(Class.forName(name), method, false);4 J7 t( `8 r2 y5 w) r
} catch (Exception e) {
: ?" ?, t! L5 D System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ V8 D) {( H4 g* i6 Y System.err.println(name + "." + method + " returns " + e.getMessage());
! w! ?+ }& C }- X( J9 U8 z0 Z4 M System.err.println("The process will be terminated.");
- e4 K5 Z L! e5 P E p System.exit(1);3 N) g% a- _6 O3 _) r* A
return null;) G2 s9 B& ^6 k5 X6 J* L
}
G# ^: s- i$ e) }2 r return sel;
- N3 {3 F1 m( j' y9 F9 H+ E }/ a8 ` c6 w" \: E1 c) m9 G, |
( N9 n. S, j3 v+ o ~" W public static Selector getSelector(Object obj, String method) {6 { T" w" N) u; X6 O+ u7 [
Selector sel;: w7 h. a0 u+ C! I+ h8 }* M! s
try {% E3 D3 [4 U" M9 q- L9 o! W G
sel = new Selector(obj.getClass(), method, false);, l }( H. W9 ^
} catch (Exception e) {
0 U8 ]4 M& [! i& N System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 Y! C7 l. _2 J# {: Y5 w3 |+ g' m + (obj.getClass()).getName() + ".");
/ o7 W. w, ~5 }7 {1 S. }' @( t System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* ^3 B2 X) j& P+ a9 m7 {6 H$ G
System.err.println("The process will be terminated.");
0 N; f$ y; Z9 ~+ O; C2 } System.exit(1);5 \8 r+ h4 o. N+ M+ u
return null;, W5 w; c) R3 R; P
}' H+ j8 P7 [ O; R3 P
return sel;3 o+ d& C! b6 n8 D$ v
}
0 ^5 {8 @0 N( p1 g" h; Q} |