import swarm.Selector;
% F- P/ U: U$ t x0 P& A. ~6 O/ D2 x4 o5 l# [3 z& G! \
public class SwarmUtils {
3 a7 w% O4 d4 a2 p public static Selector getSelector(String name, String method) {
. `% R" R; t$ P5 T; ^8 i' g- G+ j Selector sel;+ K& n* f9 K" v+ X8 B/ I
try {9 O" d" P7 x$ |- h5 J! y; f( w
sel = new Selector(Class.forName(name), method, false);
8 |3 `% v. t G) M } catch (Exception e) {
0 b; n! B. C0 F System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# A$ K" c# b2 `' i9 @ System.err.println(name + "." + method + " returns " + e.getMessage());
# f/ H+ l; X$ M9 ]4 L1 A System.err.println("The process will be terminated.");1 R( ~ s0 e8 |7 ?
System.exit(1);0 l( h/ O2 |( F' S
return null;4 V; q6 h) v6 H _' f5 g9 ?
}
- s; V; D L# X d/ T return sel;
; y; ^7 m7 }$ O/ z0 c% S, {8 r n }' \% `, M! S& r; d
6 j {8 U7 u/ z& ^9 i1 o5 E) @ public static Selector getSelector(Object obj, String method) {5 e; o: l" l% W, G2 b# |
Selector sel;
# u% o7 r' N0 j try {
, n* `) E1 ]. e! z& p sel = new Selector(obj.getClass(), method, false);
$ P1 A( p/ t$ X } catch (Exception e) {4 v) m4 t; A5 K. O w( I) N$ f4 R' m
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 R) V3 ^; c3 E( M, n + (obj.getClass()).getName() + ".");; f3 Z) o8 n" M7 t5 W
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
5 k7 B# |' E. |( i' N- @2 o4 a System.err.println("The process will be terminated.");% d8 |6 x- E$ j: k& e- A
System.exit(1);# R# `: N: v2 } y" d& k$ C
return null;- Y$ o/ n4 L; @; L+ N! S
}
7 X" B' w. R" V6 K l2 S1 K return sel;: c/ a8 a+ B9 T2 R7 @# x" E
}. G. Y4 L" ~, r; ]9 e3 B7 X+ S# w
} |