import swarm.Selector;
, u \* i0 z5 I3 B) b5 G, p- D q, k; i- R# O+ L
public class SwarmUtils {
6 Q: o6 J7 t" ^ public static Selector getSelector(String name, String method) {
4 g' u. i2 Q: ?$ z- k! N9 c Selector sel;3 Z4 T. g! _8 W# h6 J$ |8 B
try {
" H$ D; Y" q7 ]4 N& N7 b sel = new Selector(Class.forName(name), method, false);, p6 i9 U9 x, o% f4 ~; a9 ]
} catch (Exception e) {
4 J+ L/ ]. ~2 E8 e2 E, d System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: K; k' c# }5 q/ C+ R System.err.println(name + "." + method + " returns " + e.getMessage());
5 X! x# N$ l4 G9 b' p5 X, s System.err.println("The process will be terminated.");" v7 i4 ?/ ~9 i9 J. [5 h: C
System.exit(1);. y, [+ n, M; o; w4 k, Y9 a
return null;. q$ p6 _" T1 c
}
- k6 V {$ E4 U/ f return sel;2 u% ~3 Z" w6 w) N/ X
}
- M( x8 ~) x l* f3 m5 o) h) d& L& s, |$ y# ]
public static Selector getSelector(Object obj, String method) {
( O. w9 h* Z0 \3 y: R. k- F Selector sel;
% V4 w1 I- r7 ?/ z. r0 U, [* ]. {$ v try {
$ c1 e( _' Y, g sel = new Selector(obj.getClass(), method, false);2 M! O" S8 X4 E+ l; J. A5 j/ c8 { l
} catch (Exception e) {$ u& k5 V' @3 g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "7 q0 C9 p9 m, F2 ]9 ^7 s
+ (obj.getClass()).getName() + ".");- ]2 O* V, }5 W* y( s9 @
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 l5 u( ?$ t: l4 V System.err.println("The process will be terminated.");
3 J8 ^: J0 B$ W4 `+ v( U System.exit(1);6 I2 l1 Y' x0 q( t9 B: c. e) L
return null;
! k: i4 n! |$ W- r! |% m& d }
# E |& R1 ^% F' T1 B3 @! t) X return sel;
( {$ g4 ]) N9 ~# x8 r6 ^ } i8 j# K" M; [8 B! f/ r4 A- C. r( u
} |