import swarm.Selector;
* D. d! T/ {- p3 S* j2 [+ |2 l) Q+ u! R3 D1 y: P+ |. M8 j, `4 B% f0 V
public class SwarmUtils {
4 @; x0 @! q- {5 N) P |2 _ public static Selector getSelector(String name, String method) {
9 c* s( O8 h! J Selector sel;
- O6 ]0 i, w) p2 h try {
. P" t, c: Z6 h! x sel = new Selector(Class.forName(name), method, false);
2 L. v+ a s% ^* u. R( O } catch (Exception e) {: D( x- o5 V$ P+ a5 j* s
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' o6 l) F7 G& m" `. n& T System.err.println(name + "." + method + " returns " + e.getMessage());% \: U3 b6 O) {0 O9 G" x
System.err.println("The process will be terminated.");
3 Z {& V5 u6 i, U6 H4 i7 ? System.exit(1);6 H; Y3 {/ ?3 m( f6 H0 v/ M$ f
return null;
% k4 \' ~ o: p' r' L+ N }
# O _! B8 s& L8 U( s return sel;/ V7 @( {7 D. R) Y* k
}
, i) |8 j) E, l4 M- Q
" ~( ^# i9 N* `1 ~2 S public static Selector getSelector(Object obj, String method) {
+ N* N8 P5 F& x/ G1 g! ]% J Selector sel;+ ?! ~. ^$ F9 H
try {
# H$ [+ m% ^( g. s) `# \) x sel = new Selector(obj.getClass(), method, false);' p9 F" q& L+ E& X9 W
} catch (Exception e) {
6 S6 I* n: Z$ G, ^ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: ~& t7 V, B+ d1 F* U1 ^' o + (obj.getClass()).getName() + ".");
: k- `2 q0 c3 W: E9 | N$ W9 ^ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' P7 [# d2 k! ]4 I9 R8 F
System.err.println("The process will be terminated.");) ~4 n$ j) I! h9 A. _/ ~
System.exit(1);) M7 ?. L) k" @/ q( Z. {3 D
return null;
8 [% }5 V& C3 l* G }% f5 V9 _$ x2 B/ I2 Y
return sel;
6 y% ?& e8 N/ j* J9 c' z }
' R1 L- q3 B1 ?% Q* w} |