import swarm.Selector;
3 w$ X4 S% y$ m9 F8 J. I
/ h# B5 J% w5 ~2 opublic class SwarmUtils {6 |: C) c5 ^+ }+ q
public static Selector getSelector(String name, String method) {
% [% s; @ A$ ]2 n2 @- q Selector sel;
1 T5 r8 X( H! w# H' L try {
. O) `, h" `6 q6 j) K4 g. A$ a/ ] sel = new Selector(Class.forName(name), method, false);
9 b* t. E- q6 f4 q* D) G$ @( h8 p9 N } catch (Exception e) {
3 L! {% a# q8 ?. ^& d& ?: }8 w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");, ?# y i3 j! T" `) D. _$ ^! g
System.err.println(name + "." + method + " returns " + e.getMessage());, {$ |) }7 ?* K9 m8 {# v9 ^; l
System.err.println("The process will be terminated.");
/ F2 K2 r& e) @2 y System.exit(1);, k7 [+ g* r. g5 {' {
return null;
5 y& u+ U) G9 o7 N" F! ]( i }1 B2 f; `2 o$ A0 q2 e8 Z
return sel;
- U" h. G' @* |1 @" }7 J+ |( N }
, J& _8 j+ Y7 ?( H( U x5 i l9 f& J6 @; g. v2 Q, Q
public static Selector getSelector(Object obj, String method) {
& x; l2 e/ Y4 K/ y6 a Selector sel;
+ P# r; Y/ @, V2 z& ~ try {$ X: }0 h. e. { Q
sel = new Selector(obj.getClass(), method, false);
; V$ V! Z: t+ A1 i% J, b5 m } catch (Exception e) {
8 h2 X3 X2 a L/ J/ L; D System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) `5 [9 x" Y n: K4 M1 f: o + (obj.getClass()).getName() + ".");
+ [7 N: p- `" a" z5 g! r5 @% q System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 a0 r2 o) C4 k" S0 O( K1 F1 _ System.err.println("The process will be terminated.");
7 ^7 C( J Y2 v& u* }* N7 B System.exit(1);
* S1 J8 @2 Z* k7 a4 v! Q- N. S8 M return null;
( L G9 K4 a/ {5 b. v! V }0 S3 U3 q7 k3 h, A
return sel;
( D/ C' K) I( d! @; _2 c }
7 ~) |6 H+ Z% L8 {( N6 s5 ]} |