import swarm.Selector;3 ~8 f3 I0 p: C' x6 N
! `" d8 }! B& i+ lpublic class SwarmUtils {
8 S/ m4 g( M# \: D2 V' G! H public static Selector getSelector(String name, String method) {
7 ?3 N1 G3 ~: R" ?9 H' r2 x Selector sel;
" A, n: {# X8 N, M& L try {/ H7 p( f6 m7 M. I
sel = new Selector(Class.forName(name), method, false);
7 F2 W8 R$ E* o. O+ S/ d& P# E } catch (Exception e) {
/ T" K7 C6 k9 F0 h6 Y' q: R- u System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& L8 r6 ?7 J. z9 d; p; d System.err.println(name + "." + method + " returns " + e.getMessage());
4 Q2 Z; n/ M) _ System.err.println("The process will be terminated.");
6 p$ D# [) w5 x3 H k5 T System.exit(1);
, E+ C3 Z1 p6 ~) O" v return null;
! I, \6 ]7 O8 @* a1 }8 U' d }* r1 v+ @# S! j( J7 f! @
return sel;7 x7 N/ {3 W2 s4 Z' E
}
. n3 ]2 O9 z4 ], t
- T, x& R5 [ {1 a public static Selector getSelector(Object obj, String method) {7 T9 a* @3 Q3 X5 j( j3 x
Selector sel;5 h0 J& m4 @9 ~2 d' Y5 u
try {
8 |. t9 L# ^( j8 }1 b9 i sel = new Selector(obj.getClass(), method, false);
1 |' ?: V7 v3 t3 T( ~: R g, G } catch (Exception e) {
/ }4 ~: {$ b! m! Y& {: z: q7 e: v System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. m+ l+ T, u. S6 b) S8 i + (obj.getClass()).getName() + ".");
, O' O/ s! F" O! W* m' e* m, j System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( r+ Y8 B# ?2 }- |/ J System.err.println("The process will be terminated."); b' m% D" N/ N+ y8 Q; Y+ z |* Y
System.exit(1);
C- Y6 {8 K. h$ Y& E) l return null;2 v: Y5 \- K" s# J
}
. f( u. z* C; ]' h' b9 c return sel;* K8 P" z! g9 l4 a P; y+ y% ?
}* `2 R1 J, Z$ u0 H
} |