import swarm.Selector;
# s) p* `# }& q% v( \. V5 Q9 t$ N' T# l
public class SwarmUtils {
* I9 G p2 ?; A' [' S0 t public static Selector getSelector(String name, String method) {
) T' t; v: [ l0 u4 |% o Selector sel;
* }" m m5 A+ }& p& [ try {: [6 [4 g C7 p
sel = new Selector(Class.forName(name), method, false);* n, y& g# L' ?- g9 l
} catch (Exception e) {
6 f# ?9 D4 b6 o: U+ i5 P! \ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 p! F) p& Q; f3 W7 x! W System.err.println(name + "." + method + " returns " + e.getMessage());# O- ~+ R4 D6 H9 _9 e, |
System.err.println("The process will be terminated.");* a+ R2 z* Z9 A( [6 k5 G4 I
System.exit(1);
4 Q$ t# R; @' |2 N return null;" a& ~2 a- q( g- H& V
}5 X: Q" v- g! c5 e6 Q1 W4 W, z5 c, x
return sel;
( k# {) t7 L, C* o5 I" F0 {1 h }# ~% Z2 H) A, j- B* u
; I& @. C7 y5 Y! i; ~ public static Selector getSelector(Object obj, String method) {$ q; Z& j2 \: P& K0 H$ K! l) [
Selector sel;
+ A$ B6 ^9 G2 _0 F; i. W8 e* ] try {
& p" `) |* e% r: z5 ]% b+ r sel = new Selector(obj.getClass(), method, false);, z2 _. }: s' }# ^6 Z, r
} catch (Exception e) {
; y# i' n) D$ |7 i1 u$ ] System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 X! g; l5 [# K. i6 i + (obj.getClass()).getName() + ".");
2 I4 Q( y" i2 ?% ?1 [9 X- }+ F r& q2 p System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# w$ o+ r8 h& h, B4 D System.err.println("The process will be terminated.");
6 D* V5 }5 ?% v7 t9 a# w System.exit(1);4 e& ~# j1 M; J. x( C1 ~* X
return null;/ F1 D0 _8 i6 H. |; @
}9 q' Y* W3 T0 L: ^ d
return sel;( y: B& F2 p$ y
}
2 X9 w, m1 @- J( G} |