import swarm.Selector;1 Q* f0 u- B' \- n' K
- t- m6 p7 S" W* V2 V4 f& P Y8 ^
public class SwarmUtils {8 Y+ j* n# a p" ]
public static Selector getSelector(String name, String method) {# Y8 ~) A" C5 }# D+ C+ l( ]* J
Selector sel;
" \# L, G3 H- ^ try {
+ L/ X5 T3 t( K) W sel = new Selector(Class.forName(name), method, false);9 V: ^* H7 y/ ~& B$ n
} catch (Exception e) {
# c' F2 j0 @' ^0 f7 m8 E4 A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 x. \, v+ I. Q) g# C2 d
System.err.println(name + "." + method + " returns " + e.getMessage());$ Z I6 j O+ W$ n7 C- ]
System.err.println("The process will be terminated.");
$ z9 |" s/ s; d' V. A. O& l System.exit(1);, V, O7 D% ^7 ]
return null;
& H4 M& i. V/ n( }7 G }3 X9 R/ Z1 n7 w$ R1 j
return sel;1 T7 [% r3 V0 g4 w
}
! b, w, {: ]% C" Y# ^4 W
7 c/ a# g: Y1 l- D# N% h public static Selector getSelector(Object obj, String method) {. O& @! F3 q. D' n6 b
Selector sel;
. y1 g) E/ P" C7 Q2 b5 H2 r! ?& ` try {- T9 a/ K1 _2 _9 B) N
sel = new Selector(obj.getClass(), method, false);/ ?: l: X0 Z' |4 ]! Y
} catch (Exception e) {
: d7 o8 I+ [/ S; ~, r H1 g System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& Z6 o1 M; E" S" ]/ w! j + (obj.getClass()).getName() + ".");
4 r& \; k2 ^+ L2 G" {% C System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( v3 P/ f1 b- g& i System.err.println("The process will be terminated.");
+ X4 G9 A* N2 T1 v7 z" \6 J System.exit(1);
" N, `& | ?6 }8 Q: G return null;; U; a5 j. H _6 m
}& Y2 f& A# A9 Q& M9 U
return sel;4 A0 J+ x- ^/ V" r0 c9 |
}
& ?" w4 }2 ^3 ?! }, e! I} |