import swarm.Selector;! L) z+ [( j- {* U
4 e+ c* J% p0 w4 Z. M
public class SwarmUtils {
B$ O/ P- g. j( T public static Selector getSelector(String name, String method) {
h i! L8 r6 s' g Selector sel;; n. ~9 q# t0 K5 q
try {( {$ |& P" v; Z
sel = new Selector(Class.forName(name), method, false);
) F9 b; j: r8 V7 a } catch (Exception e) {1 P' D/ f" Z) j4 h
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
/ q+ \& i; x2 t System.err.println(name + "." + method + " returns " + e.getMessage());& s- W0 k, Z8 v1 r
System.err.println("The process will be terminated.");/ A1 r! f+ o& `$ |; J/ H
System.exit(1);
, f$ f$ f4 G7 F9 W0 u/ Q! q2 s return null;
) f* G6 o, Q. y# g/ ~' W }" K0 w+ M6 V+ R
return sel;
/ C: B( i1 [7 ~7 ? A/ a: m7 ~' v }3 p4 a8 A" P$ C7 I
4 m8 }3 J# w, K' u( o
public static Selector getSelector(Object obj, String method) {) O8 F l: Z6 R: D9 ]
Selector sel;
P" K+ X) r% y) M( X try {
6 V9 T q+ d5 v' F- W7 }3 E sel = new Selector(obj.getClass(), method, false);
* K- t9 N& d" N8 X" u5 H& z } catch (Exception e) {
$ d" _0 `: A3 k- e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
/ p5 _9 [# C* w7 r& w7 l + (obj.getClass()).getName() + ".");7 L+ U. ]. V6 g4 {/ z- m# e* k- O
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- E; C4 ~. ^1 i System.err.println("The process will be terminated.");) h: P% N* E5 M8 o
System.exit(1);
. T5 m% [$ \' }) z return null;
" y$ `9 G) W8 _' J }
@% E2 |+ w4 A' u. m/ G return sel;- ^2 x0 P& O& h- c5 M
}/ i R1 u/ B5 {1 A7 _7 k2 v
} |