import swarm.Selector;
* t; y, }" X2 m6 p. I- u3 Y2 |1 O; Z0 u
public class SwarmUtils {9 V3 z; g) _3 N0 H+ y( F
public static Selector getSelector(String name, String method) {
$ v( o+ d9 g+ O6 a Selector sel;
2 A% E! b& `, `( i" l7 T, F& f5 c try {
* |, V+ o- s* Y. `( S$ e sel = new Selector(Class.forName(name), method, false);1 S. K1 [( A4 X) v
} catch (Exception e) {
! Z4 z6 i$ N' S$ a) v System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' |+ k7 _4 \5 A: g K System.err.println(name + "." + method + " returns " + e.getMessage());# f& k" |/ ]# R& ]& j# i
System.err.println("The process will be terminated.");' C/ a8 q% C; [: R" O
System.exit(1);
4 @# m3 J$ T& l return null;3 s3 R6 K) z5 X, }& Q
}% u& K* {1 F- J
return sel;
. t3 E1 ? Z) o8 @4 y- v/ E }
( Y9 ~8 q; j. y% X( \9 j% i. @
) d V8 p' t; U) n public static Selector getSelector(Object obj, String method) {8 s' ]( K) b6 ~+ @- x% J* Q
Selector sel;
2 w& h! e; G6 ?. w) e6 X1 } try {
, {8 i9 w6 p. \! e sel = new Selector(obj.getClass(), method, false);
% E! w, M3 R n1 e" ?. \. _5 `9 n5 v+ p- W } catch (Exception e) {
0 t7 y L+ u9 P System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
5 L U; ^* D8 ?# } + (obj.getClass()).getName() + ".");
# Z) ?9 E: o2 A2 m3 a* D! h System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 a2 y& r) w% j
System.err.println("The process will be terminated.");% @' ^. |$ M( x3 T
System.exit(1);% W# ?0 e# I% S0 e3 O' W2 R& l
return null;
/ [! A' W7 s4 v- Y6 P }
) s/ D& R0 M& H# {# I3 `1 \3 ` return sel;
8 x+ ~9 f) |2 h$ F$ f! y- Z1 v3 L }
' \4 v4 g; P. a. r! Q} |