import swarm.Selector;
$ \* h" z7 r( E$ }
3 Y" M3 ?& w, \! Wpublic class SwarmUtils {$ g8 w% F; g; @2 X8 e$ L
public static Selector getSelector(String name, String method) {; R" z0 k+ P" j- q: ~
Selector sel;
5 J0 u) E# E4 s$ x5 ~ try {
; U& U/ g- ^# g5 N sel = new Selector(Class.forName(name), method, false);) `8 a+ j" c; [
} catch (Exception e) {
6 Z4 o0 m/ w; k S o% \ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 K/ g6 m3 |- A1 Z3 h/ _
System.err.println(name + "." + method + " returns " + e.getMessage());. l- F' R- o" I
System.err.println("The process will be terminated.");* ?: Z; j7 }2 R3 \
System.exit(1);
2 y2 d3 f7 F# h, {, e0 y! l- ?& @ return null;5 w# ^/ }$ G+ t/ [7 H* N
}- Q+ E9 O! b: Z+ ]" g) h
return sel;
7 U' Y2 B% |( c0 E5 l }
7 a3 ], y" g% o. C6 f7 w1 J. z0 l8 z2 p! e F2 {( f" @7 Z1 f9 H
public static Selector getSelector(Object obj, String method) {0 A7 f/ N. e: Z
Selector sel;
2 B, s& m) n- c. _0 L1 B% L4 n try {9 i+ C% ^- k! R( y" E. C
sel = new Selector(obj.getClass(), method, false);
1 l. q) B# |% W6 m } catch (Exception e) {4 w* l( D1 e O, P
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 v: ?3 P6 W; ^- | + (obj.getClass()).getName() + ".");
3 q3 e2 |6 Y6 ^! j' O& Z6 P; F System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 k0 b' j+ {0 I0 X, ~8 x- z
System.err.println("The process will be terminated.");
3 S: O% O6 `' v5 |! W* y System.exit(1); p J; v! @: p" Y
return null;0 y7 v4 S* @8 w# i j
}
( \/ D V/ q+ U4 e return sel;. y2 _, ^ _6 ^# e/ [& C
}9 o: B' { q7 L2 J3 D1 q
} |