import swarm.Selector;
9 j5 [3 L( c: n+ @1 p& i# T( g: r! w" v4 c8 v/ I8 i
public class SwarmUtils {
5 R2 L" D D8 H9 p" E( {) F. \ public static Selector getSelector(String name, String method) {
2 `" Y4 J5 J) B( s: @ Selector sel;
0 m5 `0 T" u; Z) J8 @" k- j6 g try {
6 |( [/ @+ h C2 h1 ? sel = new Selector(Class.forName(name), method, false);
* p( N3 H& u* f: ~4 c8 _7 y# L } catch (Exception e) {# ?0 V. e( p; Y2 M
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% g- \! U M; L* L6 ]& R: n System.err.println(name + "." + method + " returns " + e.getMessage());
j( v) @7 W9 {9 v4 J8 ]" k, P System.err.println("The process will be terminated.");! v4 u1 ~- i$ N( N$ f
System.exit(1);
; U; [& E# J0 m6 x' C$ i( R# H return null;4 \( o* o {9 ~$ w, y+ X
}, C: z: g1 Z; V9 }* M
return sel;
: c8 z) g: G8 q7 R* R3 Q }
% N" ?9 ?& [+ N5 u) T! L
( c i) J$ G8 G public static Selector getSelector(Object obj, String method) {8 }) h: ~$ p4 e$ t* `' p, Q
Selector sel;
, t$ P* ] A1 i. G/ Q8 L try {
, O+ t* G0 T- i. d sel = new Selector(obj.getClass(), method, false);, b- D ^5 |4 Y) @* R
} catch (Exception e) {
4 ? n1 P. T+ ~; h; A4 K System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ U- k2 n7 k+ b + (obj.getClass()).getName() + ".");
, w# r- y( R% L- q! J* m System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' K6 b! f9 E9 O& j
System.err.println("The process will be terminated.");. L5 n! M$ t" x6 g% q9 X/ a' p
System.exit(1);% q# u" S& t" B l2 `
return null;5 N' s: D/ t! G4 p Q
}
/ B5 p, O/ @6 \. m5 | return sel;+ g. _0 i) O( ]. s0 g% G L5 B' o
}
! w1 E$ G2 p$ Y, F: u8 i$ V9 w} |