import swarm.Selector;8 X0 Z& N5 T0 B
z1 A/ i) T& h" Jpublic class SwarmUtils {
; L$ M4 {$ l! W1 [0 @ public static Selector getSelector(String name, String method) {
. Q; k, k1 w4 C Selector sel;
! j4 E k, p1 V2 s" |+ n try {, W3 M/ h7 [/ l
sel = new Selector(Class.forName(name), method, false);
+ l' H" x% [( y- M7 N- ` } catch (Exception e) {+ |0 u7 h/ ^6 N' O: c" D
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 Z2 x! r/ j$ S System.err.println(name + "." + method + " returns " + e.getMessage());
. P( @# _! |" s5 w1 Q _+ J# {5 R System.err.println("The process will be terminated.");/ e" b: N. ]7 T* Y
System.exit(1);
^4 a" Z- q4 P/ z return null;
% w7 U# z! S/ y! `( B5 A }
& t& a- X3 d9 I2 o! G7 o return sel;
* n+ _0 D0 y, y( s! ~ C } x* s& \ X' i, ?- M
% P- S1 m) a5 \- p
public static Selector getSelector(Object obj, String method) {
1 F4 u5 T5 ]( U9 }, C1 W" t Selector sel;8 w1 z( F. b( v4 p0 G
try {3 I7 A' i0 \; {+ e1 O! P% ]) ]1 d# r
sel = new Selector(obj.getClass(), method, false);
' d: @" K0 [* }$ U } catch (Exception e) {
# Q7 K2 }0 Q& M2 e: n* Y; h System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
, x2 w3 P t$ m: x + (obj.getClass()).getName() + ".");
9 |6 c7 L: K& ?- T& k3 i1 W) { System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 ^- y# C' x. ?9 n0 g1 K System.err.println("The process will be terminated.");
3 ?. o6 f! q. u& M3 d System.exit(1);
( ~% u4 J% e% D; e return null;
" G% ?4 }" ~. ^( W# T- H" g! i }7 g! q/ C3 k& i' p- q& b
return sel;
0 x2 \+ m0 w, r& [5 h2 l2 d; A9 W }
) _7 F% i; J' l8 }) Q6 D8 F} |