import swarm.Selector;
; y1 x1 g+ N4 t: g2 F2 V2 i6 j K( U/ o( G6 @8 ^) G5 c" w5 N
public class SwarmUtils {9 V. q; C. H- y: C: _4 O9 h
public static Selector getSelector(String name, String method) {* W' M0 E' [" I
Selector sel;3 [+ g3 Z% F: J a# d6 H+ F: w
try {( Y& s) l2 K+ b ~8 ?0 ^8 {1 E
sel = new Selector(Class.forName(name), method, false);2 v% h6 P/ D& h' G- T
} catch (Exception e) {' H8 A( `3 \7 t
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& H9 ^7 F# q, n8 v$ s- o4 t System.err.println(name + "." + method + " returns " + e.getMessage());: X4 K u5 ] c, y3 M, _
System.err.println("The process will be terminated.");3 O2 {- e$ [/ }& q1 y- T$ L1 P, r7 j
System.exit(1);
' `2 N/ ?6 s6 m2 |# P% M' y return null;6 C- K; c, X8 s, l+ G
}
5 w+ @+ e% v* l, d& z return sel;
5 m1 Q2 ]2 i1 v } y+ }) g& R4 t9 L* j2 z2 n; C+ ?
' S* }6 ?: M4 `3 W+ } P, a( E1 z: a public static Selector getSelector(Object obj, String method) {9 u: Z9 _* I- c
Selector sel;
: v9 z! _+ w! u m K( k& Q try {
; D& ~: z) ^4 S1 |: Q, G sel = new Selector(obj.getClass(), method, false);
{5 {5 ], v2 K9 ? k0 t% t } catch (Exception e) {
9 T) E/ f z) [" L2 V+ g5 V2 i System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% z2 P s- e0 J) ]3 z! L
+ (obj.getClass()).getName() + ".");) ]8 Q' w% r# U
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ C3 \: E# m# a. V# c
System.err.println("The process will be terminated.");& j3 `% I% d5 G ?- B
System.exit(1);
" w+ B. z4 F* K2 E. F& L! u8 t return null;
! \% O3 e6 D$ f6 N/ l }
; C' }6 l4 d+ t' x% ~ \ return sel;
8 _+ R. u& n7 U# @) R" ?/ a6 F1 U }8 n+ j ~9 H4 s' [' ^4 M
} |