import swarm.Selector;
+ W$ }- I2 A( t# D6 h7 M+ K
" y8 m6 O" Y5 J' F1 d9 E4 kpublic class SwarmUtils {
" L9 K* n5 O9 H" T5 i; H9 n5 W2 U public static Selector getSelector(String name, String method) {% ~% ?: m! A1 {2 O& {& B5 k
Selector sel;
- s' U3 T/ w5 g' R3 o5 b) y9 S/ [( o try {
! H0 w. U" \( N- { sel = new Selector(Class.forName(name), method, false);
+ }0 M- Q: o% p6 H/ N) j; s& a } catch (Exception e) {
% L, G; ~( v/ s8 t$ d7 P# J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 I+ @3 y1 D4 t5 s System.err.println(name + "." + method + " returns " + e.getMessage());
$ ^6 l/ \4 q2 W3 E+ f System.err.println("The process will be terminated.");
; U- E; Q+ h* `$ R/ O* \# T3 U2 C System.exit(1);
4 ^& e. C/ s5 s5 F" y return null;9 |6 S) q% [# f6 l
}
2 U. y8 S5 J& ~: I/ A! {- b return sel;
3 ~/ P' ?. X% A }$ w! ]4 g4 j) S: F* Y, I
7 r: V. j% F9 K/ J public static Selector getSelector(Object obj, String method) {
2 N% g7 x6 f! ~9 K2 h4 f+ ^8 s Selector sel;- ^# \! Z( m+ p
try {
$ d/ J+ M m* A0 w sel = new Selector(obj.getClass(), method, false);
! H/ D7 A! f' V$ ?+ o `9 S6 @2 w } catch (Exception e) {
& j! }2 K1 G9 @7 ]1 Z( Q; c: d System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' B5 g0 D7 L' y5 t' G3 s
+ (obj.getClass()).getName() + ".");
# \# o. N. l2 D# _% q System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 W I1 @5 a( @ System.err.println("The process will be terminated.");3 y0 W& @, a: _! S4 h
System.exit(1);
7 R% C5 ?5 i6 |" Z# i return null;' x2 d8 @- b) F7 e y! j
}
$ s" s! q; @- G* w9 B- l, V9 J9 k return sel;* x# `/ { G0 P2 a, Y
}; L( G. J8 q! K- X( I1 @
} |