import swarm.Selector;
! d7 y Z, P2 q+ ]6 b. ]6 ]( m! h( l6 c! C
public class SwarmUtils {
8 Z8 |+ M A* f5 S public static Selector getSelector(String name, String method) {
d% l$ U$ B) t6 h% k9 N( J% n, Y Selector sel;+ g2 G) {0 U2 p: U9 w2 W. P0 Y
try {
! T" t+ B2 ]3 R. L4 T1 u7 D1 r sel = new Selector(Class.forName(name), method, false);8 t. m4 R) l! f8 q( _
} catch (Exception e) {
3 Y8 R5 N. R0 K8 T+ f0 B2 ] System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: `# U8 x3 I# B% A3 ?& G; a/ X7 _
System.err.println(name + "." + method + " returns " + e.getMessage());
! S [. P: W& H7 O- q% O6 h$ R) K/ x System.err.println("The process will be terminated.");
/ D- o" A+ g* I( n$ e System.exit(1);
9 n1 @! C, ?4 t, W$ p0 U return null;
% \4 g, }* O2 v6 k+ ^+ g }, \* m6 w0 K) W( k1 @" S% l5 y; M
return sel;8 e4 g9 X) n- P! b( Y) E
}
8 w0 R- G1 w2 U( T, v& o7 U+ F7 G% D. N4 ~# ^/ m
public static Selector getSelector(Object obj, String method) {8 g8 o6 E( A8 E# u; H
Selector sel;, H+ h& \6 V- ?- ?# U6 b n
try {
1 @6 r0 P3 d4 G$ x% H! N sel = new Selector(obj.getClass(), method, false);
! e% L; c5 W0 y' g. s! a } catch (Exception e) {+ s6 X. D* o! G. {2 T
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 D3 ]6 |4 r U0 N$ }. ^, S
+ (obj.getClass()).getName() + ".");" |) ]% ?. M# }8 z. q
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 f# W0 o2 ?+ _# H6 ^7 ~2 ? System.err.println("The process will be terminated.");
- L {/ s6 ]% i! o# l System.exit(1);
2 [- E9 V* N3 H# Z return null;
" f# n( s. i$ W }, P1 k1 w6 e. K0 h
return sel;
; G/ [1 ~2 U# H+ H5 p }7 Z( X+ ~9 ?3 x8 g4 w; K: l
} |