import swarm.Selector;
4 j. F$ W" s) b# e4 f# F
% G9 w0 r4 O: ^4 Dpublic class SwarmUtils {6 O5 c( u' T& C6 ~
public static Selector getSelector(String name, String method) {
! Q" V; @1 t7 U. U Selector sel;7 D* Z5 D( Z! B+ U, j6 i0 l u( H
try {; g; A# b& n7 s K" a8 g
sel = new Selector(Class.forName(name), method, false);" H. W3 s$ ?8 A2 k& |% _- @ C( P
} catch (Exception e) {
% M0 Z# H5 m3 x, F8 ] System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. _) d3 h5 j+ Z4 d5 K6 _+ G( e System.err.println(name + "." + method + " returns " + e.getMessage());
$ D# n- K4 B; h System.err.println("The process will be terminated.");
x: Z; T! C2 h0 S$ B System.exit(1);& [" [0 M" A: v2 _2 d( |
return null;
& d+ v/ ~5 ~: D/ Y: ?8 z" D }
2 ], T$ S. @* `1 L* o return sel; l. F, z. x7 h; ?# l8 j6 J3 Y T
}* F3 d( Z) d4 p# c/ w; K
7 X j& J7 X$ e" ?9 ~; {
public static Selector getSelector(Object obj, String method) {- \$ d! J+ v# M, s& ~4 j
Selector sel;& Z) |$ F. T$ f9 c. s/ D
try {
, P, b* d; {1 G) s3 \* E2 F" Q sel = new Selector(obj.getClass(), method, false);
7 E0 t3 X6 o: b( l# V6 L } catch (Exception e) {: z, Y5 N9 Q3 y6 j0 }8 z. c
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 m ?. J& C8 t- B& ~ + (obj.getClass()).getName() + ".");6 `# u& Q- _. s
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* t( P$ n2 _; R3 S System.err.println("The process will be terminated.");8 Y% K# h0 B' H9 l' Q: l
System.exit(1);
: Y4 L; A6 h6 w4 v% X return null;
1 P8 A4 } H4 \2 r5 I! l+ c0 D }
: |6 @# v: s' a5 ^/ O return sel;+ c6 _2 `$ Z1 y" ?0 W2 C
}9 @1 e) p" H; ]& {( b& Y0 Z
} |