import swarm.Selector;
7 ?9 |5 \! X5 }5 s; B k' H1 F' {' ?+ {( F& ^6 J7 N) l
public class SwarmUtils {- P5 O( `1 ~% u
public static Selector getSelector(String name, String method) {
8 A# Z% l6 }4 j( C9 N+ _ Selector sel;
/ y! p3 M( j, B3 D try {
0 W* p, l. P0 `8 Q2 _' x9 |4 ~ sel = new Selector(Class.forName(name), method, false);
" \; q4 i w( l# U8 S } catch (Exception e) {
4 x/ {! p1 J- z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 l- `! F4 L0 v+ |) r0 c, \8 s System.err.println(name + "." + method + " returns " + e.getMessage());
" g: @# [! F# S System.err.println("The process will be terminated.");
9 j& V6 Y* Y! u+ b0 a System.exit(1);
R; G# w; @$ A% i2 d return null;2 L8 a& u! B0 A
}
" m2 g8 T9 ]7 e1 b return sel;& p5 z3 b/ v8 ?1 F/ U
}5 a' x9 |% j, L
! X- a4 K8 p5 x4 v public static Selector getSelector(Object obj, String method) {
1 B2 b. _% ]" Q5 i* K1 [( M8 N Selector sel;4 G2 |; ?+ |! X; ?/ B
try {; T2 R; P8 D) e1 P6 P
sel = new Selector(obj.getClass(), method, false);4 |! T( n$ H/ ~4 A
} catch (Exception e) {
" M. T, m2 O: A% n System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& V8 O; P% h, a& H) [
+ (obj.getClass()).getName() + ".");7 z& b7 O( q# n! h" o0 ?6 U
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( G6 x$ I5 E( q7 d) _0 p1 n System.err.println("The process will be terminated.");* k0 _/ [" ^# T0 _2 d) m: ?
System.exit(1);. d8 H/ W* N& g) `7 l3 f# z
return null;- G+ W% d- Y4 M
}: L* _6 ^% w& o( ]7 h; r( _
return sel;! }0 f/ u: V7 U/ O7 i3 W
}
# |$ B( ?4 B3 A1 I c6 |} |