import swarm.Selector;4 d) K6 m0 G0 M
4 O% u F/ j) v! C8 E( S/ ~! epublic class SwarmUtils {
' H G. [4 c$ t- q0 f2 b) c& a public static Selector getSelector(String name, String method) {5 l7 m- [3 j+ J. N0 `1 c# e) m ?
Selector sel;
" w, O- o4 s4 z+ X- L try {. `1 C' K* Y# g
sel = new Selector(Class.forName(name), method, false);) B8 @" h( N: d* A% O+ u
} catch (Exception e) {
* W7 c: i0 ?0 A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
1 M2 X+ F {* S! r2 g4 I System.err.println(name + "." + method + " returns " + e.getMessage());
* r* S, T4 o0 O* s8 J3 L4 Z System.err.println("The process will be terminated.");
6 K5 [7 ]6 v5 @: c System.exit(1);
* w* C' L& m) L% {9 X return null;" B) {+ z- [7 o
}
\ T4 W% Z. ~9 f; ?6 G5 M0 i& a return sel;# l' b! o1 J2 K7 a7 p& X6 T
}6 Y1 }0 k0 d. X. z. f0 [
1 ~3 l4 x) D4 M public static Selector getSelector(Object obj, String method) {0 q: ^' E8 ^1 \
Selector sel;
# m( X' }1 \9 Y9 | } try {
7 R* m' w* x1 j# T6 M& ?1 K0 J sel = new Selector(obj.getClass(), method, false);
6 T8 u6 W m5 Y% s$ `, s. I } catch (Exception e) {
$ u$ e* \, b2 r7 o6 n6 R( o System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ K: @- Y8 x5 U( L* {! `# X( _
+ (obj.getClass()).getName() + ".");
8 V2 z2 P+ \- V9 d Q System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 D8 J, J% X/ E2 y) U System.err.println("The process will be terminated.");! s6 o- V. r# f6 J& {& y
System.exit(1);$ u& N/ F0 @4 l: C
return null;4 a8 `% i7 J6 M( _" d1 |
}
8 x0 Q6 h5 }% b, e1 f return sel;
& n8 h8 H. H" v4 a: e8 e6 E }
& B1 l- N% L1 S+ _" t8 n! m. G} |