import swarm.Selector;
" r$ |/ i; b8 T# N! K9 N7 j4 i8 |+ B
public class SwarmUtils {
: ~4 w# S, v! U1 w public static Selector getSelector(String name, String method) {
$ W7 R+ W4 f( `3 y- [2 i1 X Selector sel;, H+ r! R2 _+ ^8 ]# n# C
try {
7 d; h0 k/ c8 Z sel = new Selector(Class.forName(name), method, false);
( q8 B8 V6 e# s: |# B, U9 N } catch (Exception e) {
7 Y. ?8 d4 O9 E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 e: W, V. k" a/ e Y7 _) H: e System.err.println(name + "." + method + " returns " + e.getMessage());
& x, o# g1 H; d/ W l System.err.println("The process will be terminated.");( X1 K. K# ?. _3 i
System.exit(1);
6 }0 v* T! | M5 U+ p8 w8 e( c5 X return null;
, G0 R; ~! |6 |' Y0 u" S! j7 Z- z }
' k7 g3 H$ q9 t$ Z5 t; h( | return sel;) \$ X% v7 o# ^( d# o: Y$ Y
}# ]" a9 Y' l. { j4 _
9 m7 c6 Q* C, C3 \ public static Selector getSelector(Object obj, String method) {. `# H6 {. K) {+ ^. D
Selector sel;9 i5 l. W, I) F$ x' h& a
try {
4 C# `: h; E/ j8 C7 ^+ U! ? sel = new Selector(obj.getClass(), method, false);
{# ]+ V J5 ]+ E; Z. O/ k8 \2 P } catch (Exception e) { |2 v% F( J5 L8 C( O, t: a0 ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 g( O3 [' w& b( ^+ E
+ (obj.getClass()).getName() + ".");* W: V3 U1 @# h9 r4 R8 [
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 C8 w( i! u/ H. \7 \5 J System.err.println("The process will be terminated.");
( {1 @8 C) D1 D7 c7 t0 y% d9 g System.exit(1);
. f( u' p1 @# X' [& n# J return null;
5 M# W. u' T D9 F4 ~2 i$ ]8 O }
7 d# A+ [2 u: Y return sel;! ?. m8 s8 W1 x& Q* Z- p" z, H& f
}
% Q7 X7 `4 w) X0 S/ U} |