import swarm.Selector;
2 _+ k9 C; u0 J3 H1 E$ q O. w* R( E
public class SwarmUtils {
. g& W5 s+ G- r$ `/ \* [6 D- @5 H public static Selector getSelector(String name, String method) {
# ~/ c* r/ L- O& w& b, r1 y3 s1 x Selector sel;: A9 X! H# [- g K4 j- l8 i+ j! L$ }9 B0 K
try {% e5 c& t% k2 ]
sel = new Selector(Class.forName(name), method, false);
8 @' n8 g+ h/ Q. c: H0 b } catch (Exception e) {" q1 {- b+ t' C; _$ H" P) G4 T: }
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 r3 u) |' a- v9 S# s System.err.println(name + "." + method + " returns " + e.getMessage());
5 |' U' B0 h1 d9 o2 G" v) i1 k System.err.println("The process will be terminated.");
1 o% D. ]- [/ \, Y \ System.exit(1);
& M3 H. s7 |8 y7 C" b return null;+ {: d# b' Z% s4 g5 I
}4 \! n1 r0 X1 Z" w
return sel;
, U$ O( H7 ^. Z7 D" Z }
* B5 \% g9 [" P3 {$ L) ~& b; s6 ~# H7 X- s6 R2 T0 o
public static Selector getSelector(Object obj, String method) {
6 W8 ^! o( L* j8 b/ e! p Selector sel;
# p+ E6 X$ A$ V3 P try {5 [3 n0 F% p: I) X
sel = new Selector(obj.getClass(), method, false);
+ G. v! V! v8 I2 h. @- r, Q } catch (Exception e) {' Q( ]+ f$ \) M2 c% U
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", S7 ?+ W$ U% I% S) m0 K0 Q
+ (obj.getClass()).getName() + ".");
6 X9 b& ?4 p7 M y, T System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; \6 q7 v) b0 A+ U
System.err.println("The process will be terminated."); Q" E8 y6 m/ Q+ ]
System.exit(1);
8 a1 e- X3 P# O: }# T return null;
- b/ C( D& B. Y+ o. r }7 w( P* |8 E1 g) G* a2 x- ~
return sel;
5 A2 ` ?- p& q( {% L) n4 [2 l2 e }
" O; C4 W- y5 Z} |