import swarm.Selector;- N& e4 k7 h4 H4 E* \1 P
; {, g& s, b' L# Z
public class SwarmUtils {0 k& \! I4 r& o; h; n
public static Selector getSelector(String name, String method) {- s0 H' C" g% p
Selector sel; s$ L5 W5 [* W+ @, O9 v
try {
, p4 u4 Z2 b- \: [* M( Y sel = new Selector(Class.forName(name), method, false);
2 z. g$ I. M1 G& F- b9 t0 P `8 E } catch (Exception e) {- A) x$ W4 d/ y! y4 m6 l- y' n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. i0 E) r' v. [9 n System.err.println(name + "." + method + " returns " + e.getMessage());) G, G& q1 r8 Q! O) i# \7 Z
System.err.println("The process will be terminated."); e3 ~5 B; i( b0 E& S/ P
System.exit(1);
- A* s# I' T2 \2 T; r* o return null;
% A" E* P9 P& W. f& [- n }$ m' e, h' m( X
return sel;; ^% g( K: a5 }
}6 k' x8 p, k/ g+ ^/ X. s
) h" u J: s# k1 M8 B: }8 ?
public static Selector getSelector(Object obj, String method) {
# W, p/ d; u2 t& H Selector sel;; r7 ?& @, W+ T4 v; w+ k8 C: f$ t9 D
try {! O3 j# _6 F. @8 u
sel = new Selector(obj.getClass(), method, false);
( _1 }6 v. G6 E( [: O% ]7 V } catch (Exception e) {
* _0 N' B3 y+ [$ |* p, [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% n% n5 K6 N) l( i
+ (obj.getClass()).getName() + ".");) V& l0 G" o$ o% S `5 p
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());4 M3 _! n! c8 T* y
System.err.println("The process will be terminated.");
3 |0 O# O& k4 Y4 S/ T System.exit(1);+ D" w& y. r) S* d" R7 p
return null;* ]! w: e3 r6 M) h3 Y+ `+ p; Q i
}
: V: F" l9 }) p) |1 J return sel;" [! F1 L7 D+ U# ~& d% E6 H& e
} v; Y9 z8 Z7 F! P! Z
} |