import swarm.Selector;
8 a1 \2 h8 ?5 [# h1 @# w2 N+ |9 R. F2 ^4 k
public class SwarmUtils {5 f) c, K+ y h2 ^
public static Selector getSelector(String name, String method) {
: d+ I( K1 X( Y. L Selector sel;/ |5 g! T+ L% I- O* V3 z) F! v0 L
try {; h q1 g2 x/ q7 p3 W& u
sel = new Selector(Class.forName(name), method, false);
, w" b$ I$ ?6 W k( E } catch (Exception e) {
" @/ h; ]6 \ G: ~1 ]" u' t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" ]4 A5 F2 |* e7 ~& s
System.err.println(name + "." + method + " returns " + e.getMessage()); E1 i( m- E" ]
System.err.println("The process will be terminated.");
1 Y9 R, _/ O B6 A% }2 Z System.exit(1);, Y/ C8 O3 J+ Z' c* T9 V
return null;
. J: Q6 ^1 l) y4 i. |8 [2 } }$ \" |; H' l2 D5 p0 v( ?5 a
return sel;
- L2 y6 _' _1 H7 K. E$ w }: B) h/ Z; _! E* v* F( L) b. \
+ q, R! ? O/ I public static Selector getSelector(Object obj, String method) {8 Y& A% B0 K, l% n6 k0 n8 s5 b
Selector sel;+ v& _; A% O/ f" U
try {! h( L6 Y \3 w2 |/ p5 U6 a: k
sel = new Selector(obj.getClass(), method, false);) A5 k4 Z0 e" ^- @
} catch (Exception e) {
: ~& q, J, n' u. ?: B System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& y* V5 W6 w$ |/ w o7 M
+ (obj.getClass()).getName() + ".");1 Y+ l( _% Z r( K- W
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: E2 N; M, G! d+ ~+ d, f System.err.println("The process will be terminated.");
! L* d* m2 ]/ W5 S! A System.exit(1);# f8 J+ _# S& [* L$ y1 {
return null;
! b( @0 O9 H4 j, s% f8 n6 H7 @: Q8 c/ A }! ~; n0 A% x( x$ _
return sel;% k7 x/ l# z: `, f) a9 A) D% T+ d
}
0 G# P8 m* U, W} |