import swarm.Selector;
9 L& j' H7 ]* U9 h" |( n: I) b7 W9 x
6 K$ m- U1 X) x. H9 Y/ N- m9 ], ypublic class SwarmUtils {
- \& p$ H. ] O R% a2 T public static Selector getSelector(String name, String method) {* E) t+ Q4 t4 g8 _" ]6 F- U# C
Selector sel;
U# v0 m! }' Z( A6 S2 K Q2 I5 ` try {" a& m: ~) v3 h6 c) {5 z1 Y
sel = new Selector(Class.forName(name), method, false);
( v' j5 N/ I" b8 Q) a } catch (Exception e) {
$ T: m0 R% e, Z2 c System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" C q: N2 q- v& y5 r- _
System.err.println(name + "." + method + " returns " + e.getMessage());
: o C+ O' \4 w0 T6 U# F- k( e6 F System.err.println("The process will be terminated.");
! B( T9 q8 [9 R- g System.exit(1);; `+ p4 C; R& \% P* ~* T! ~4 D
return null;$ O- N* m+ T8 {& Y
}* u2 l2 f+ l4 g! g1 m% e2 K& W. ]0 i* B6 J
return sel;5 p$ v! \7 S2 K1 j4 g6 X2 y' @
}% `* T- s' t6 {. `; s' r. M6 i' k
0 c* S c3 Z0 M- L! O" R6 ]% F* N
public static Selector getSelector(Object obj, String method) {
: Q0 s4 C) B. W/ W" N: M Selector sel;: T) q5 N8 _$ I8 v- s7 X( G2 X3 X
try {# Y8 b! u; t4 b2 W+ u
sel = new Selector(obj.getClass(), method, false);2 n& K8 W2 Z( A2 o* \& H
} catch (Exception e) {9 ^5 U( g6 F2 {. \' r# u! h
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 d) E% R/ r+ L0 b5 w2 k2 q
+ (obj.getClass()).getName() + ".");
+ g8 T9 H3 d3 b: D- Y# E System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 d5 h4 I* }0 L0 x# `$ V System.err.println("The process will be terminated.");* q" W, c' E: z6 M
System.exit(1);
5 r- s# O+ X5 c1 H" t; }8 t: H return null;
0 M$ h; Q# E8 f' \/ O, b3 Y }# @- V& o! y& q9 c, @2 V9 P9 a T
return sel;$ {+ a% s0 `$ i; }$ C! i, q9 C. E
}, S5 E) \& y5 `, o; g3 Q
} |