import swarm.Selector;
7 R' Q2 }4 s; k3 G/ T: M
: U" h# r9 r5 A# b. Upublic class SwarmUtils {
. K3 A9 t" Z" ?9 U; ]) w% i# J$ } public static Selector getSelector(String name, String method) {# X. m" x" [# N4 m9 c8 E/ }
Selector sel;# y, B2 `$ a' m
try {
$ S( K) R6 U: U! Q sel = new Selector(Class.forName(name), method, false);
2 E8 |( J1 w L; _. F8 m- C. f9 s } catch (Exception e) {
8 `8 U, J( u; U' O0 O, }5 y% U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; |7 p# }$ G: o8 U" O System.err.println(name + "." + method + " returns " + e.getMessage());6 X% ^6 H( B* k, b
System.err.println("The process will be terminated.");6 j# R p* G# ]4 _$ e5 G8 c. A
System.exit(1);8 ]8 C% T: ?! X% E
return null;
0 D- ^: q" \$ O) X8 Z }
' F' c/ G9 F" _3 F- W' z+ H return sel;
. y4 J5 P$ H" Z/ T }5 `) n; s2 |/ `+ Z% I! ]; S6 {3 O Y
* z5 X+ `3 R( l public static Selector getSelector(Object obj, String method) {
' ^+ C. h$ l1 @) k9 w0 U. P Selector sel;
# p" J5 X, p# b! e) @ try {
7 ]5 B, D* d% k7 V+ S sel = new Selector(obj.getClass(), method, false);
4 o/ l$ P* p4 {2 p1 i/ c. w( | } catch (Exception e) {
% M4 q' P% j0 i, [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: d6 k( [+ p( R. H8 |0 s + (obj.getClass()).getName() + ".");
0 E9 a0 ~0 Q4 B9 i1 d System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());& y5 i3 i8 l3 P: j6 W: Y
System.err.println("The process will be terminated.");9 S3 B9 F6 ~& [6 O4 k
System.exit(1);
! y6 g( i3 X% k- {* Q7 ] return null;
1 }( V. Q) B* |1 n }. X# E: N) s k
return sel;
8 x3 n" L/ _9 W4 V' z0 h( U! | }0 s& w7 q5 L5 s+ g7 F& s
} |