import swarm.Selector;# }7 M6 q3 e5 @& {5 Y
+ l' m+ f* u: ?! A& Kpublic class SwarmUtils {
# D$ m- u0 a% q* d2 U U public static Selector getSelector(String name, String method) {
. g! ]' ^' M Q Selector sel;7 A' R# p4 j; ]8 m
try {- P: M& Q# c: \
sel = new Selector(Class.forName(name), method, false);
8 W6 K' |/ F* t% L1 Y! D } catch (Exception e) {
$ D9 I* Z; p% J# Q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
/ h* w$ K1 y6 S3 a! M System.err.println(name + "." + method + " returns " + e.getMessage());
4 H0 T6 _6 o7 P! Y& e System.err.println("The process will be terminated.");
" z" v: N7 H6 G% r" `3 o! S C System.exit(1);
0 O$ V5 D/ r/ l( J return null;! k% K, i/ M: Q% [& F
}
: u2 n R5 W8 E+ F% r v return sel;! n7 x' a* E9 U0 c! p3 e- b% z
}
( I4 P. |- F# X5 y& _7 u! j' }6 ^2 o6 ^+ N
public static Selector getSelector(Object obj, String method) {
3 x K2 \! l+ k Selector sel;
- r ?' Y9 Y+ ^* J' \+ W: ?2 c try {
& P! g" K0 M' g: D: M. Y sel = new Selector(obj.getClass(), method, false); c6 p9 |6 ~+ z
} catch (Exception e) {
: v& `2 @$ N0 s* U* T3 z1 n7 Y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% J/ L& x' Z( w3 \, i
+ (obj.getClass()).getName() + ".");
) Y& k- Z% ?# S: w+ c System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 f3 g6 Q4 h4 a" m System.err.println("The process will be terminated."); i8 |7 I4 t- G: Z5 z- }: _
System.exit(1);& S5 D7 r2 w# h/ A8 Z& X" H0 ?
return null;; r7 x L' m" J" v' E
}
- Z0 M: i$ x! o4 \, @ return sel;' `6 @ y3 ^2 q9 o
}( P6 L0 [1 J" v
} |