import swarm.Selector;
9 y# h: T4 L' e3 b+ {" a' T1 f+ A8 D8 m# P
public class SwarmUtils {) j- |4 N6 y. s; A
public static Selector getSelector(String name, String method) {
6 \! O7 C6 x" d# u, k Selector sel;3 {' {( H1 ?: w4 ~' G. q, `
try {2 |2 N6 g5 f" F! H! [2 D; \
sel = new Selector(Class.forName(name), method, false);
J& ~. b1 g& a0 p+ P } catch (Exception e) {% s: |5 W1 g) H: H$ n( `
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" b1 Z, [% }, m3 f/ P* H System.err.println(name + "." + method + " returns " + e.getMessage());
2 r) A! u9 |$ V( a6 `$ u System.err.println("The process will be terminated.");
% Y4 B; f% Z) a. |) z, C System.exit(1);7 q& U6 L6 B: n
return null;
. Y# {) Q/ p3 S! i' i, M }; Y# C$ L$ d! c% i. D, a
return sel;- h' Z& w# V9 Z' U
}
9 O$ C/ @& k0 W# R4 @& B
g: g8 H" J. I public static Selector getSelector(Object obj, String method) {# m2 q8 V8 Q6 [
Selector sel;! o+ i( T* g# X( G
try {
% }4 D _6 y7 _1 N: ~/ w+ x sel = new Selector(obj.getClass(), method, false);
! L# p% Q& p1 G, R } catch (Exception e) {
, Y$ R" W- J. z* S System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# u* N( `, [" y* c0 S; D3 q5 A+ \, c
+ (obj.getClass()).getName() + ".");6 m# B' v" l$ S! w6 z8 X
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); X& a0 S4 M: T' l, X
System.err.println("The process will be terminated.");
: z2 B$ v( f! l" z+ {5 s4 O: ~ System.exit(1);
& T& w0 [, k' Z) n* d/ y return null;
8 u) n& ?; b x D, A }
- @6 x. Z5 e: R. \6 F/ M l/ t return sel;
- g& r2 Z# F* ~! k6 ^3 ] }7 J# q6 \5 C2 A9 c
} |