import swarm.Selector;, S! m* {1 N% }4 o
' L' j5 i, w0 p1 H& d2 d; h4 {
public class SwarmUtils {" T4 T% r0 P, |5 `
public static Selector getSelector(String name, String method) {( q$ t# L$ y7 e' a+ u
Selector sel;7 |! v* y( ?8 [# l, K1 q* }9 o$ w
try {
( r7 g- v# F) H3 V- K8 u2 f sel = new Selector(Class.forName(name), method, false);
( I3 @9 A( b# P0 R } catch (Exception e) {& E3 _" `3 p: F/ D7 {
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' @6 R9 l G& ^5 p J# r0 o$ t System.err.println(name + "." + method + " returns " + e.getMessage());0 ~/ L- q/ f" {3 G
System.err.println("The process will be terminated.");
, Y/ D' z4 m, e2 d System.exit(1);
* {% b' n/ a* O9 Y" R( Q return null;3 ]$ ^5 y0 s' R8 j) ]! R
}
7 m/ q' p# N% X f return sel;
% ]" j) h) F, a5 C }
5 n) W5 e: B- A
: @$ z+ z4 ^- }6 P public static Selector getSelector(Object obj, String method) {
) N( _/ g8 `# k" t& O Selector sel;
2 v, ]: H; A! h. G+ Z7 g3 E try {
3 |/ U: ?! F! x- t2 `: \1 i: s sel = new Selector(obj.getClass(), method, false);
% y0 ^1 Y+ `. e3 Y! ? } catch (Exception e) {
2 K( W7 z& M6 c! m1 V( {. ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 e: @. j! g2 X% \$ Y + (obj.getClass()).getName() + ".");% w9 v P& N- {* S8 F! _
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- ^) _( V3 ?6 Y, U, l# r System.err.println("The process will be terminated.");
+ J2 d% Z* J x9 l, H/ Z System.exit(1);
) e5 j3 P, I4 Q# Q7 _7 ^: n return null;
# d1 d9 {3 K$ u: ~- d, c( W, Y } C2 r; T1 N" l! @3 m
return sel;
* T1 M) z) {% V/ P }
- ?* C% @! K6 }9 O+ \} |