import swarm.Selector;1 L6 a2 C) L4 a; z0 ]
, B- x6 g* ?% B/ @* d T7 v3 d9 F- `& u
public class SwarmUtils {
6 q$ V- f8 w& F1 n public static Selector getSelector(String name, String method) {, g; s/ S, |$ L3 `5 f, Y, Q2 }
Selector sel;' Q" F/ d1 M6 Q' L8 @# A: C* f3 O
try {
9 j0 Z9 W( A; }. b( n sel = new Selector(Class.forName(name), method, false);
1 u% C7 ^3 Q8 d0 [1 B } catch (Exception e) {
+ x+ g' ^. a$ M+ z0 _) `; Y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" ?7 S3 S5 s1 a6 d: p1 |! i+ \ System.err.println(name + "." + method + " returns " + e.getMessage());
+ _+ S2 L& o8 ]& X. a System.err.println("The process will be terminated.");
" c1 m) B) T* {7 t" `5 B, Z8 [! o8 k System.exit(1);
4 w: r% N7 Q0 G. F. Z( A return null;
* s% j3 c( g$ T3 P" r: V" a4 f }. ^* x$ z) w- K/ }: L
return sel;
. r: l; x" y+ f G$ N }- c, t/ V+ e! K* Q" d8 F* C
+ H% i- D% K* K
public static Selector getSelector(Object obj, String method) {* w* t6 i+ d ?0 F9 A8 P" W
Selector sel;
c s4 U. w5 [, f5 Z$ q3 ? try {
" }2 o( D7 p" V+ X# t sel = new Selector(obj.getClass(), method, false);
, C; G- [+ s; n } catch (Exception e) {
{6 R( P2 r% a i6 U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" ~* A Q/ u9 Z7 I" p O + (obj.getClass()).getName() + ".");
, n! f$ W) M8 G System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! D9 _) d9 u' w$ f) H
System.err.println("The process will be terminated.");1 x3 s; I& v& J' r/ P0 U
System.exit(1);
! \& a) z( ]3 L return null;
: y: j0 A$ c3 ~5 c( v }
7 x( n' O0 ?- g, ]/ S/ { return sel; d: F3 g% ?% F0 }# t0 C1 w3 ~# M
}
' }/ D7 a1 @. o4 |. Q9 Z* {+ P} |