import swarm.Selector;
% W# Z" i: C( `1 H8 X* D. Z4 X+ w; F! T( o
public class SwarmUtils {- ~* R% V& e2 A$ N
public static Selector getSelector(String name, String method) {
1 K9 }% T h/ T# T { Selector sel;
5 N. r5 H' P" @( C& O' ]' A- q try {
6 @9 q0 p- v* E5 E sel = new Selector(Class.forName(name), method, false);7 e. L+ f7 k! q( x
} catch (Exception e) {9 x8 p% c8 U. T. o$ \! E
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 ~ L, o! c6 j1 ]: P% H4 Q' b, I
System.err.println(name + "." + method + " returns " + e.getMessage());4 f1 y' Y/ V) D8 F1 ]( T1 T
System.err.println("The process will be terminated.");
, f/ z! u, t) @ System.exit(1);
* g% I( D3 |+ r' P& k! i) H return null;
/ y- ^8 y" o( y/ s }; J3 r0 G: L) W* S! M
return sel;
+ R1 ^+ g, _4 l% e9 z. u }
' |, n# }( q A/ H f& \$ e3 b) p) ^: U: ?2 r: M. }9 ]+ l
public static Selector getSelector(Object obj, String method) {2 G8 n; @9 Q$ X0 |8 K$ `
Selector sel;
; {" ?4 [& [; D6 E( u+ W# W( @+ R try {
' |6 |0 ~; `8 M0 a/ [ sel = new Selector(obj.getClass(), method, false);1 ?% P. Z% j: p7 ^, n: I/ a7 O3 u
} catch (Exception e) {+ r% Y+ u" x9 b' r
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. Q" i3 }/ X. e& J + (obj.getClass()).getName() + ".");
& _1 k% c* [9 Y: S- s5 n+ T System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 n. C8 ]$ ^) O1 h5 u& s( H
System.err.println("The process will be terminated.");
3 _3 V2 y0 v3 z; Y r7 b System.exit(1);3 C7 V' b* S7 g D, j$ w8 l
return null;" q3 H. `4 G- C' C3 x
}
# _+ ~; C- b0 H/ s return sel;* ^: l1 d) T& b$ n
}
3 x- k' M, r( {2 d2 p& a: P7 Z} |