import swarm.Selector;7 G* |* ~, L* J+ |# m, R
, i" m& P6 _. @% ~public class SwarmUtils {
+ A% G! B" B2 b" J0 p7 z2 H- b public static Selector getSelector(String name, String method) {
, h8 r; K3 H# }; R% P Selector sel;4 b/ J& U. p2 w
try {
. a8 i2 w5 j s+ L/ G! f% \8 U sel = new Selector(Class.forName(name), method, false);5 J2 f& I2 T: C9 M
} catch (Exception e) {
4 Y+ S3 Y4 C: C' {: g System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& N- N' e# ?4 ^% Q- J4 s$ m- T System.err.println(name + "." + method + " returns " + e.getMessage());
5 a! n2 x. q' ~- r) b: f& x System.err.println("The process will be terminated.");' v/ ?; S6 m; S% c E9 r8 T
System.exit(1);
6 d6 A. {) a% j6 W/ n' g* r2 b return null;
" A6 `% i& f2 n, C7 y: }3 ^! s: _! d' n }
0 O( _, w6 E& |( r% v3 ^ return sel;5 F3 o! K1 O% d! i3 E T+ C6 E
}
3 f q7 d, ]* Q4 X, l$ }( m' x( k( m5 u
public static Selector getSelector(Object obj, String method) {( W" G- z) A0 f* X
Selector sel;1 x# O( }* x, E- l2 t
try {- X# ?! R. n9 E* b9 B- q
sel = new Selector(obj.getClass(), method, false);
1 T) i. U* e3 H2 z) Q } catch (Exception e) {
, g% d: z/ `& D+ ^ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
2 i3 c4 l; e9 L + (obj.getClass()).getName() + ".");- w( x1 m7 w/ E: U. \* L
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 ?; W% w: \2 q6 _- i System.err.println("The process will be terminated.");
& u# [. M7 C& M( T! K" X System.exit(1);8 |# |( _) {0 ]1 j& Z6 s9 i8 `
return null; X( B I, w! H1 @9 f& w& B
}
8 H1 t. z. D3 Y1 Y6 n return sel;
2 ]7 E, B# ]' Q1 q& g! L } w) R- E: j+ Y* `, n4 f# b
} |