import swarm.Selector;2 Y: P! C5 l. ~% R A! ]( m/ B6 T
: B" [8 K. Z. z# w$ U; e
public class SwarmUtils {$ l( I0 l+ m; U9 t" A* z
public static Selector getSelector(String name, String method) {
v$ h' b) `$ Z; o' b+ B1 H Selector sel;
- s) X. X: {2 K( Z2 k4 k# o try {
{# w0 Z9 W( d! Z8 T1 b* {# x sel = new Selector(Class.forName(name), method, false); W; S0 a1 u( |
} catch (Exception e) {
6 ?& l) M) }1 U4 T System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" v" P: ]' }' k System.err.println(name + "." + method + " returns " + e.getMessage());1 O/ G6 _$ K8 N* Q- d
System.err.println("The process will be terminated.");
8 D# V+ j1 w4 m4 ~$ Y& C2 Q+ X6 k System.exit(1);
" ^+ ~4 Z: c, G* W9 ]/ \/ u8 m return null;* y) c; I) t2 z) z9 `
}
6 M# Z4 Z9 }! c* F. } \/ H! p u return sel;* ^8 S/ Y; M4 o8 |
}
6 N4 ? }; E: D( P1 T% h
! g7 c: A: j5 | public static Selector getSelector(Object obj, String method) { W- u6 z4 C+ z5 l
Selector sel;) O8 F# A( H% P4 {$ s* Y. v* |/ N7 z
try {: V( s8 ]6 q- y
sel = new Selector(obj.getClass(), method, false);* }* |: Z3 w- I: {6 ^
} catch (Exception e) {
. V; D: k# H$ H6 l9 z) Q& t' ~* ~: t* n8 l System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 i% i6 o! E# _+ a7 O/ V + (obj.getClass()).getName() + "."); y! p3 O! v' t! @; e2 J
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ f. }7 W( g6 x! D m+ A5 w System.err.println("The process will be terminated.");; ?- }- L; b3 f) @& }% ?1 G7 c% {
System.exit(1);
: R) l4 M6 ^, s+ k return null;
+ t& D. C2 g) M4 y5 k }4 K$ R! p4 j# M9 ^! U
return sel;6 \" |8 g0 S, I# P1 _
}; F6 V0 x: m2 v5 k y4 B, f/ ^3 Z
} |