import swarm.Selector;
7 C# {. q! C8 ]/ s7 q1 ~, u- {3 }0 j( d- A8 V
public class SwarmUtils {1 g! P# |. N; @* J& l2 h1 ?2 c
public static Selector getSelector(String name, String method) {
0 {/ u( f. K! v" C s6 i3 [$ t Selector sel;
. R F- P3 `$ \" t2 k try {4 S6 E% a3 w& O: m; Z/ G7 l
sel = new Selector(Class.forName(name), method, false);, m: f& l' X C- d8 V. W4 r
} catch (Exception e) {
" H- d! v6 U7 B6 L System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
L& \% [# z8 p6 r2 o3 K: \ System.err.println(name + "." + method + " returns " + e.getMessage());' F' X# H7 D% ]' M `8 S1 w1 _1 N
System.err.println("The process will be terminated.");
$ Q- x7 Z$ K/ r J7 k) C Q0 k System.exit(1);
2 }% s: O! C2 \& D; ` return null;# M3 B5 u- z" \7 y
}
& h( g1 b" |5 e6 G2 }# Y3 L+ c: S return sel;+ f) H$ g3 ~' Z$ |
}
# p; H- N( K- l ^8 e: s% t; P, i% h: m% L
public static Selector getSelector(Object obj, String method) {
5 e4 I# u X% o3 h4 z' t% Y4 k+ b Selector sel;
+ I; l/ U( r! `3 d try {
& |: q( @) a& Y* L% `! ]( Q0 Q sel = new Selector(obj.getClass(), method, false);: A0 F* a0 v3 j B# z% r
} catch (Exception e) {( k+ a& H6 P3 m! i1 y* O2 n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& v( N' z/ w& O. C7 ]
+ (obj.getClass()).getName() + ".");( O! v$ ^+ X. G% d- E
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# R* `) o2 _8 J3 k' f/ R System.err.println("The process will be terminated.");
' H; [# w$ O3 H3 l4 o System.exit(1);
3 I7 O8 L: ?3 Q# Z7 j9 e return null;9 `5 A6 y( a' S
}. O0 p0 U5 _! w
return sel;
# c4 s/ W. @5 `* y }- N3 Z8 c8 a/ ~0 V o
} |