import swarm.Selector;7 U& @; s8 h8 L+ j% H0 r* }& a
; A! C9 K8 G3 p6 D z B; y( ?
public class SwarmUtils {% Z) P- S7 X: ^: I- ]9 L" |: S+ }/ J
public static Selector getSelector(String name, String method) {
% f2 m# Y! s) Q! E! U* o3 m Selector sel;
7 i' |, b+ B/ a' L try {
# v* F0 o9 w9 s5 u1 I% y+ _, u sel = new Selector(Class.forName(name), method, false);" Q9 o( U- H4 ?. \ o- T" E7 r2 S
} catch (Exception e) { l1 r K/ f' v4 J( I
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! e" q+ x8 N2 [9 k- L' B y System.err.println(name + "." + method + " returns " + e.getMessage());3 e$ j% q$ c( y' `
System.err.println("The process will be terminated.");0 V5 j$ V6 T! n5 U5 g9 [/ f
System.exit(1);( Y. B' N! S' I* n/ A( y$ w
return null;
8 O" F2 x" o# E' Z9 V ]6 A }
' U. s. ^. W) l. Z) g, X! I7 h6 V( ^ return sel;. G8 K8 `! @& D9 |5 ]# x; q
}
1 Z8 ~% s0 U' b1 b9 s( v; O3 u
6 M7 z+ T2 c& `6 `, P public static Selector getSelector(Object obj, String method) { m: r! Y8 v* W9 {& G# B0 ]$ A/ ^
Selector sel;! |; z. W; u: s# g; H, ], o- a: ?5 p
try {
' J* e% M1 V3 }8 K i sel = new Selector(obj.getClass(), method, false);$ T1 }5 Q$ Y: ~# z1 k
} catch (Exception e) {
; f6 h3 I; \4 A; u System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
5 W2 e0 {# B1 c + (obj.getClass()).getName() + ".");* I( X" \6 A# s7 o8 H
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. D: z0 s4 l& ?, t$ G `
System.err.println("The process will be terminated.");
, X- Y; ~; f; V9 B% y& o System.exit(1);% Q( n/ v8 S! M) L, j/ h* N
return null;- p5 _( G& b, I, O b/ ]8 |
}
0 Y; |/ p4 {/ G2 P# _" @ return sel;
P0 `0 D( k. k. P- I }
* }" t/ w# x' \* t! }3 P: M} |