import swarm.Selector;
; i* r U- \( H2 L, r" G% j `$ t7 Z3 J
public class SwarmUtils {
0 y& K/ _/ |" `* }2 A' t8 C- g. k public static Selector getSelector(String name, String method) {. H& E, W1 F* U' k
Selector sel;
+ }/ f9 Q7 G- v2 _& p try {
4 w1 {9 V* r. l6 m( l! g) N sel = new Selector(Class.forName(name), method, false);% m4 G. y: D% J& Y7 x3 d5 Y- q
} catch (Exception e) {
1 k2 E) S, ^, P/ T' Z0 A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; @0 J, ~: {( I- C
System.err.println(name + "." + method + " returns " + e.getMessage());: W+ |7 U4 d0 s6 S. p6 u
System.err.println("The process will be terminated.");
% u: S, j+ x- D, m3 Y3 | System.exit(1);
' s1 w* T( j/ t4 l1 N7 f/ b/ x. z return null;& s- j2 I; k) |* [
}7 V- H5 }1 ], x* d5 [
return sel;
9 `4 f5 t4 p0 R. ~ _ }, s6 T) B1 C! Y* \
( w6 s5 E! h3 W& a0 A3 \) T6 U! A public static Selector getSelector(Object obj, String method) {
# w+ S/ d1 i! g2 ^$ K3 @( r: R8 A. b3 } Selector sel;
- i U. E% `: @& y3 F/ m7 X1 K$ Q% H# X7 w try {' f1 |3 |! O" {: R/ A$ ]' g
sel = new Selector(obj.getClass(), method, false);
3 A* d% j$ ?( u: b; k% d8 t } catch (Exception e) {: H |- C5 F1 c4 @
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% E$ P$ t7 \8 p: i% H8 E$ P, J8 W3 C + (obj.getClass()).getName() + ".");
5 h. l4 y1 {0 l" z9 L System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 l6 @9 \0 P5 ?' T System.err.println("The process will be terminated.");# S8 q9 S5 `3 t9 N
System.exit(1);
+ c8 ~5 Z& R0 M/ C- ]( W/ F return null;9 q5 {2 R n( ^6 |3 g
}
4 C* ?2 b/ t& M/ [ return sel;
& g$ h/ l# ?; {/ R6 ^3 {2 X }/ F0 `7 I; u) z7 k5 R* P
} |