import swarm.Selector;# B# |& v1 A% E) X: j! d
) l6 J4 G, `. w5 @5 kpublic class SwarmUtils {6 G; y9 D3 C d3 g! o3 _3 s
public static Selector getSelector(String name, String method) {
! w8 F+ |, ]* h7 Q Selector sel;
2 a% A+ N y- Z try {: @/ o; @/ k2 K. P# g% ~
sel = new Selector(Class.forName(name), method, false);
* r* ]: F4 V. H. {# ^ } catch (Exception e) {0 @* o& }% r* @# t
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");' J! N( k% U5 e
System.err.println(name + "." + method + " returns " + e.getMessage());, m4 g( R, K- y ^2 c9 B, a
System.err.println("The process will be terminated.");9 p0 D0 u& b0 \. ?' Q7 U
System.exit(1);
- c2 O! q# Q1 w return null;/ H4 C0 }4 A3 K
}
% q- ?1 H1 z( g) ?8 A: d; e4 x return sel;
1 C; {7 Z/ t1 W- I }# ~- K+ o9 O- ]2 T
8 {! H& S# l+ A
public static Selector getSelector(Object obj, String method) {
5 _' z6 \) N0 g/ \: N" ]% K Selector sel;
U; u7 ?3 F |! [$ d X8 O+ u try {
, B6 `- w( ?% ^5 `" f: o sel = new Selector(obj.getClass(), method, false);
9 B9 c( Q" Q0 f r" k/ U3 E6 W+ d } catch (Exception e) {
, }* p4 N" t M+ S1 _- p! ^" y% T System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; ?) Y$ X; V1 W' }" k* }
+ (obj.getClass()).getName() + ".");
$ a9 l4 l. j3 C ^. k0 `8 A System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); P2 F7 d7 N- B& u
System.err.println("The process will be terminated.");' T" L/ w9 e5 L) V
System.exit(1);; S5 z+ x, f9 E# y
return null;
% ^+ Q; ^! M' W4 _ }" R6 x& `% }/ i$ N: `$ I% w2 b
return sel;. r5 x/ x4 ?# a3 n. T3 q$ ]# f
}# ^; P7 p5 J: x6 B, Q' |
} |