import swarm.Selector;
# i- q- w8 M/ J! K, R. U5 k0 N9 Z, R' S3 @' `; q) F# l
public class SwarmUtils {
5 r) |$ x3 ^# M1 g9 f public static Selector getSelector(String name, String method) {3 K2 o6 [# d+ I& K% T& q6 Z
Selector sel;
) m. |& L$ K. T4 | try {
2 _- l& V4 D( L; |) ^; b* \0 ~ sel = new Selector(Class.forName(name), method, false);$ K, L* @& r: K" H s- C$ F
} catch (Exception e) {# d: L' z; u+ n6 G0 j7 S& I9 ]$ y" `
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
/ w) l2 @) W& h8 u System.err.println(name + "." + method + " returns " + e.getMessage()); J, p2 e: s& a) C
System.err.println("The process will be terminated.");2 Z6 P! L- d" y z' W+ W4 e* I4 k
System.exit(1);8 A3 Z( w. k# F: a( U6 d
return null;6 Y9 r5 P6 x H2 d
}
. g a: V9 W9 }2 k+ f return sel;0 G- E) M; z% k
}
& X# Q1 d. D$ @9 P6 \0 e ^
8 c( V+ x ?: @ public static Selector getSelector(Object obj, String method) {
+ e! z% a, t0 z* x8 V Selector sel;9 F% w. v5 `5 h5 _5 }
try {+ v+ H$ r- W( E; j- W- M
sel = new Selector(obj.getClass(), method, false);# F; X( f) _& a
} catch (Exception e) {$ l2 j" \2 I/ D0 v) E$ y! p
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% s# D. n# f$ A$ ~8 E
+ (obj.getClass()).getName() + ".");* @* _0 C6 W6 ^8 a# Z3 w, z, ~
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
; h" G! I! A' h3 }) k" ]) T System.err.println("The process will be terminated.");
, o' X8 o( U- V# ~ l0 o: P. c System.exit(1);
* M9 P' C& N( s% v( s# [ return null;# q/ y7 B3 _" \! A0 j" O: {) e# x
}
6 D3 ]0 {/ X1 K9 u6 {; Z6 d return sel;2 o4 L% O; _# Y7 U# b* b" G
}* @3 ^) v2 |8 R' @1 w
} |