import swarm.Selector;) ]' v1 S/ q- D" V6 }" x; @$ P7 Q2 I" ?
+ K3 s9 r6 L1 t# e3 W4 X
public class SwarmUtils {6 n2 }/ G z; w9 q) I1 A) I0 ?2 R q
public static Selector getSelector(String name, String method) {( V( F% L( R" Z- w- g2 T
Selector sel;
) m9 X: Z9 O0 \1 Y" X try {
5 Y" d7 y5 X0 x8 f, z% } sel = new Selector(Class.forName(name), method, false);: Y8 |* w$ y" @ O' i
} catch (Exception e) {% V6 E; F" F. A$ U- W7 K7 D. y
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ M1 R/ W k- `! n( D# | System.err.println(name + "." + method + " returns " + e.getMessage());
7 \, m4 Y* Z A* h System.err.println("The process will be terminated.");, O5 a- x) g0 n' k' v
System.exit(1);6 V0 ]( y6 X- I$ ]; }
return null;
9 |7 b5 F. w- r: R+ ] }
0 f$ Z a& S. o return sel;5 K3 Q. o& m# C
}' N! M+ M( j$ e- u5 `( A1 @
3 Z% ~% g6 J9 ` x \- y' p
public static Selector getSelector(Object obj, String method) {
$ F) V, B4 Y# ^ Selector sel;9 B/ k2 b" W4 v' b# S b
try {
/ G! ~: k" i2 m: {' U M' O5 V sel = new Selector(obj.getClass(), method, false);
2 L! t- T# G" } } catch (Exception e) {
) g6 M3 {) M1 n, e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
?) ? H" p% ~8 r( C$ j- T) u; K + (obj.getClass()).getName() + ".");$ _$ ]* ^% h: @4 N2 \' _' @7 T( y
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 j" A6 f; `6 g+ C* B" H System.err.println("The process will be terminated.");
$ d. m1 a- g1 l e T System.exit(1);
- A5 x# L" ]; u$ o; o! f3 x return null;
% L# e4 U3 X4 _9 s) y2 z. P. e! T }
3 ]6 h# r V( M1 K# M* r1 Q+ a return sel;/ j J2 c4 s& O5 q! e6 n! |2 g& ?8 p
}
: G# E& N0 q; n# y} |