import swarm.Selector;
z( r& d: F% a& a: ^. _8 A+ A0 g: t8 k& V( L
public class SwarmUtils {
o+ W& R) [) w/ ?: L; n) R( l public static Selector getSelector(String name, String method) {
2 L! F: v/ j2 S Selector sel;, _6 T6 n, i0 y5 b3 O
try {# k P7 U- a* p5 @, n: ]7 H
sel = new Selector(Class.forName(name), method, false);
" w6 \# \: j" Y# i9 B } catch (Exception e) {
3 e' f( w# i$ ~7 B; k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) Q. b3 c. ~% ^. } System.err.println(name + "." + method + " returns " + e.getMessage());
- d( X8 c8 @0 w* q System.err.println("The process will be terminated.");
$ o! i( E4 \' e System.exit(1);. m3 @; V) L7 W+ k
return null;6 O7 ?7 X/ t5 r
}' Y4 S5 y& m. P( b% @) b6 {7 M
return sel;
. Z0 M; D1 X0 q. k1 K } R: u# p$ `) y: D( m6 S
1 m6 T; X( ?3 v) r" C# J, b) x2 v: L
public static Selector getSelector(Object obj, String method) {) `5 X) p l+ U& R+ k
Selector sel;
% X; a r4 w7 m try {
$ w4 x7 R( _1 O& e) l3 C sel = new Selector(obj.getClass(), method, false);
' Y& B+ n8 P$ Z& T% E9 p } catch (Exception e) {+ t& w5 k8 |+ b* A- D* u* y4 G
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& R" Y, q/ P9 i# j8 K) ~
+ (obj.getClass()).getName() + ".");
" v% w6 h" p/ X2 _6 h: K$ R System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 e7 r( \$ G/ Z/ k a. F System.err.println("The process will be terminated.");
6 t: H4 R9 W- }6 f$ s! C9 d System.exit(1);
/ F8 Q* j4 X1 r; i1 F return null;
- ~8 b; n7 o! g }5 Z3 a" E1 p9 V" q3 h1 n1 F$ e" h
return sel;; Q' }5 c* }( O. ]+ H
}9 S; ?8 }, b# Q a7 V
} |