import swarm.Selector;- O8 d1 L! @" g3 a, O
z1 O/ r1 l0 f5 e' p4 I
public class SwarmUtils {$ ]' x4 e4 ?3 l% Q1 i2 v
public static Selector getSelector(String name, String method) {
5 Y m. g# U# i# C4 z' Z Selector sel;
& d) {4 W7 A C2 a j* L2 u try {
' \+ G0 i/ _7 e) f sel = new Selector(Class.forName(name), method, false);6 \( k2 C' K. U; Z
} catch (Exception e) {6 `6 |- M5 k {& I
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");) U1 a# Z6 G' u! D' E
System.err.println(name + "." + method + " returns " + e.getMessage());
1 W. |! m! h' X8 o System.err.println("The process will be terminated.");
0 A0 p# d7 t7 t) S' S System.exit(1);
/ _' ?+ v: |3 |# e1 B" ^# l return null;! q, h e- D1 F6 Y
}
. R/ A+ a D- i( G return sel;
0 F9 ^9 ^# ~% N3 r }
# X+ f6 l+ ~: t# ^% D- M" ^4 P# P4 J/ d, ?( d' \3 j
public static Selector getSelector(Object obj, String method) {5 y# b- f5 d' \# o
Selector sel;3 x* m5 @1 K# D: N5 j
try {. l, I9 h/ X& J! ?6 y
sel = new Selector(obj.getClass(), method, false);# p4 S8 v" c% W1 A6 M5 c( R. w+ y! Q
} catch (Exception e) {
1 i1 D. Y" j' B& c% F- h) ?4 d System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 r# h& ^$ r/ o9 J) l + (obj.getClass()).getName() + ".");* G4 m3 o9 P4 {/ r" L' H, V
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' L! j+ ]6 |) M1 ^% d) ~) ~* Z7 H
System.err.println("The process will be terminated.");7 @9 |& b3 Y3 F& @: D# m
System.exit(1);
" L) Z1 y4 Y$ @) m& | return null;6 g; q) R# k7 h- @0 I, Y
}/ G. @. A$ C9 A1 f. b4 B# ]0 z
return sel;
0 b6 D, ]4 O# [ }
: j1 k" U* v. J5 p2 {: L} |