import swarm.Selector;% y3 s0 t. r4 b6 r. ] Q
, l7 m n+ i4 h- J* S+ B* N' m- jpublic class SwarmUtils {
; @% B- p& Q) f1 r public static Selector getSelector(String name, String method) {
5 k/ o! T9 K. K' F5 |5 v6 } Selector sel;* b) \, j- z5 Y* w
try {6 @1 L0 g- t0 h# z
sel = new Selector(Class.forName(name), method, false);
+ i3 O+ S3 P" Z! C+ e+ G+ B } catch (Exception e) {
, J5 [ j& g$ u System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 a2 t7 I' T8 X
System.err.println(name + "." + method + " returns " + e.getMessage());+ a5 J6 o0 F& H* {7 V
System.err.println("The process will be terminated.");
0 M5 J6 B! n( W D4 h$ z System.exit(1);
, D4 \" X3 l& t8 i) z% Q) S) c9 F return null;
9 w" S$ U/ X* ?4 e' n1 h" F2 G: R" w }4 e* `0 J2 Q$ w5 d# \% r
return sel; u l1 w7 e# e* [' [! j h
}
7 B z6 `2 G) W- Z$ T2 B
8 [3 i$ v8 k7 x2 C. \# ^ public static Selector getSelector(Object obj, String method) {! q+ @- ^+ K& S8 y
Selector sel;
, y% b& _" `6 \% v/ i: o4 @ try {
6 M$ d' I( e4 V sel = new Selector(obj.getClass(), method, false);' t1 J# S2 y8 R- H
} catch (Exception e) {
& W. a+ { D* _+ y6 {' Q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 X6 F0 X ^4 M9 h6 O
+ (obj.getClass()).getName() + ".");& b( {: O/ k# m U
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* C: V6 u2 m0 g7 d5 p
System.err.println("The process will be terminated.");
( M9 C$ j* r/ g3 y7 F$ c System.exit(1);
) W+ f4 T- s) P/ [- N return null;
+ N. c2 b' Z0 q. i2 n }
& K r6 }- P. N0 I return sel;
% d4 `' t+ ^9 X7 p. Q$ `) _& @ }0 W; m3 H) `. n3 j* i
} |