import swarm.Selector;
1 _9 `4 |2 L6 c% B, T8 J) D& s8 n5 O9 [$ _5 ^1 Q+ d
public class SwarmUtils {, T2 g& {& j( ^2 s6 `
public static Selector getSelector(String name, String method) {% F T! H: ?# K4 I$ A- \
Selector sel;* |2 [" x7 U% o( x- U, x1 n8 x+ S0 B
try {$ z. g0 A# J8 \/ \. [# |& p: s
sel = new Selector(Class.forName(name), method, false);8 P) Q) w) `& {# ?
} catch (Exception e) {
9 k @* d. B/ U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 \( P+ H9 B4 _' K
System.err.println(name + "." + method + " returns " + e.getMessage());
, z7 v8 t9 g' ]+ l1 i2 F; s1 ~; L System.err.println("The process will be terminated.");: F5 m, T7 S% v5 v, f) G+ Z
System.exit(1);
w( Q* X \. ?0 ~- m return null;
. f2 X2 B+ f3 q }
9 l2 b/ u5 A- t- H w$ @ return sel;2 b+ u/ N# P: |2 o
}( S9 ]# |- r2 q( s2 e* h& Q5 x
# r. W+ t. x8 ?" [2 f* [5 @
public static Selector getSelector(Object obj, String method) {
, p9 a0 C. ~ C7 S Selector sel;
' _: J, b8 ~0 U* O2 F try {9 {+ E+ q+ b: S! w g H8 K W
sel = new Selector(obj.getClass(), method, false);3 J" q4 X: z- h. z* H
} catch (Exception e) {
) I, U/ m/ y" K+ N+ Q8 K1 |' ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 x. z- t. F, q- B B& p0 @, T
+ (obj.getClass()).getName() + ".");, b" D# p4 F% c* \# m& N
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 ?; e) Z! r! e$ I) C. E, Y
System.err.println("The process will be terminated.");
& n- I) v; b) g' q9 i% X System.exit(1);
! V3 F4 Z# n! H/ V2 x& N return null;! ?* ^, S' L$ K1 }7 S F
}# ]5 g C R: ?( B6 M2 ]. c' {
return sel;$ U3 ^# G( t! }, e5 v, D
}% O$ m, A& u. m4 q# u. V
} |