import swarm.Selector;
) ~9 i1 Z0 h. X) [1 q0 M# _. p6 n( M. C- o' {7 z: b2 i8 W
public class SwarmUtils {' X3 z& h+ I, s/ C
public static Selector getSelector(String name, String method) {
9 ?# N% S; ` U' V+ b Selector sel;
5 [/ h3 o, `% d1 D try {% [5 m6 t7 b! f1 A# a
sel = new Selector(Class.forName(name), method, false);
, a' I6 l" C2 |" u! m } catch (Exception e) {
# O M0 i# m9 B$ W8 r7 e+ @ A0 Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& {% A2 _- B* B z7 w
System.err.println(name + "." + method + " returns " + e.getMessage());
2 n3 P. b! X8 S" I) w+ n1 G9 C System.err.println("The process will be terminated.");2 M, q) D/ g- `/ E; ~4 s2 g6 Y
System.exit(1);
5 e8 t6 \+ h N; g6 V( h return null;
9 J2 A: a; J2 C2 D- f }% z$ U9 J' d, x l2 x4 _
return sel;, O6 ?0 b; G3 K
}
6 P2 q; f2 K1 _. @# u( X7 H9 Q! E; V- E p
public static Selector getSelector(Object obj, String method) {1 I# s7 k# M* Q3 k- d
Selector sel;
. z4 t; q8 n( G9 [ try {
: m! ?& d) p' v- F% b+ e sel = new Selector(obj.getClass(), method, false);6 g$ v8 @. H; \, N2 ~
} catch (Exception e) {
, Y3 A- H, I5 } System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "( j: O7 e: ?$ c/ h5 a6 J
+ (obj.getClass()).getName() + ".");4 j2 |" H' |7 o0 C* u8 c' w
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' F% U4 a8 r3 x
System.err.println("The process will be terminated.");
/ i7 U! c. [4 J; t System.exit(1);$ }9 y8 U! i* e$ _2 B, z: n, {* a
return null;
: T% h! B2 P* i! W" H& h) W }# T# F, q! m9 {! b F3 @# G R
return sel;
" O+ n' v2 A3 D" F% J, r }6 x& t& ]5 f; _
} |