import swarm.Selector;% h/ Z* q. k& H+ c$ N; A/ K( C
& K o. c7 [* s* [4 Jpublic class SwarmUtils {
# T+ W# Q/ F' W% J" M% e public static Selector getSelector(String name, String method) {4 Z; ^2 z4 W; U" N9 c x) N
Selector sel;
. [7 {) Y. o8 z1 b6 _ try {3 `: e: O' e* j
sel = new Selector(Class.forName(name), method, false);
! K# L# Q) l0 T } catch (Exception e) {
3 e/ C g8 B5 L# X9 k- d System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 \5 D7 U- r: G$ x' u0 I System.err.println(name + "." + method + " returns " + e.getMessage());
3 ?* J3 a$ [. v' k System.err.println("The process will be terminated.");! E+ W/ i: G7 v, s9 N" } R
System.exit(1);
) `7 s" W) b1 A Y& ^# H& r8 ~ return null;2 o& z% B- [! m
}( q* g2 f* e' B* w0 M) A3 V
return sel;2 e4 ?- ^4 @% S
}
2 H4 e, S: p. p+ C5 T" s" @5 y, E* D& Y- P
public static Selector getSelector(Object obj, String method) {
$ |6 W* Y' z- H' u# f+ J; ]; A Selector sel;
8 A% _4 k, u6 Q' W+ D try {" p9 _- V! V8 Z6 A; k
sel = new Selector(obj.getClass(), method, false); b+ T4 M# f+ f0 H% p, ^/ }
} catch (Exception e) {+ l" g; {1 | {4 _2 F
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( _: R/ y+ t4 o: I& M* K9 U6 N) ~ + (obj.getClass()).getName() + ".");
# @2 P. L: m4 x. L4 n& z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, Z* {; X6 L5 @/ \: p4 K System.err.println("The process will be terminated.");
* ?% T2 m4 @; C; s$ n System.exit(1);- N7 B0 G6 A, x! q, U, _5 u/ Z
return null;
, `; D, D7 Y6 x% m8 q1 S }4 t; U% ` f6 O% f! x! z0 s
return sel;, x# Q. V$ P3 p
}; ?, {9 K0 U0 N7 `- ]) ~. W1 N# j
} |