import swarm.Selector;
8 z8 |: G- q2 B- j t/ _& r
* x0 A1 {+ N; ^* F2 ]) e5 h4 h/ ppublic class SwarmUtils {9 l/ Y* v* s5 n `5 y. Z( ~ }# a8 E
public static Selector getSelector(String name, String method) {
* [" R) J/ p9 W& A7 \( V o Selector sel;" T: D9 h! T- k" v; ^
try {
( s7 e; b- ^0 v2 S$ U sel = new Selector(Class.forName(name), method, false);: q7 w( r# g& x3 a1 N# x9 d8 F4 a) y
} catch (Exception e) {
5 h( X' u; Y& f8 e% P. x4 w5 v System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* L; @9 [7 z( L' j" g System.err.println(name + "." + method + " returns " + e.getMessage());
. Z: f% H6 p$ ^9 e; K; F System.err.println("The process will be terminated.");+ R! i0 o2 Y# }- a p/ o2 v2 m
System.exit(1);
/ [. R8 {4 S& ]! ]7 L6 \. J- @ return null;
9 |& a( p" V1 l6 [, c5 s" f }; B8 C3 a) p8 h2 ^" x
return sel;$ {9 S# }$ S- C0 ? h
}
4 P6 C6 u) r8 d4 I8 y( O8 k
& V- J4 F1 D3 F: X! i public static Selector getSelector(Object obj, String method) {2 z$ V% `& `5 Y; S+ E% c
Selector sel;' L6 B& Y$ n0 p' n
try {
+ S; m# Y, y. @; A6 H/ `! ` sel = new Selector(obj.getClass(), method, false);
& ^2 K5 m; j$ c9 `0 [2 D% a/ o } catch (Exception e) {
6 C1 g% H/ M. Z# y" V. D3 @ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& b5 p6 Q3 E1 T& t: [# n + (obj.getClass()).getName() + ".");2 _. O4 |* V* X) o% @/ y
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ w3 m$ i$ V8 J System.err.println("The process will be terminated.");/ M( A0 k- h: z
System.exit(1);; c& K4 i& [% W
return null;
" r: z+ d1 I/ g }
0 l8 Y8 L, o+ l1 E: N( l3 V return sel;
" ]+ h( u& V( w6 L9 @ }4 B+ q+ X4 W( s2 \" y: g
} |