import swarm.Selector;4 ]+ R* Z, Y1 x+ e9 K2 J
" ?9 ^1 Y1 c ]# `8 _# W$ z6 D( K i
public class SwarmUtils {! P/ Q+ w/ u8 G# g2 r8 _; I
public static Selector getSelector(String name, String method) {& x3 z: U6 [4 e7 t
Selector sel;- p7 E" Q# J& E6 r# r& }. J
try {
& {! V/ F2 O0 x sel = new Selector(Class.forName(name), method, false);$ T: a: ?4 d1 c4 O3 X
} catch (Exception e) {+ H3 t4 M9 b6 L& r
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 V! c! w! g& y# H System.err.println(name + "." + method + " returns " + e.getMessage());9 \# w4 `/ M/ T
System.err.println("The process will be terminated.");8 J$ J& W' t4 C; {
System.exit(1);/ e' W: B. V* z, Y6 e; A1 F
return null;7 C E8 u: d6 ~, q. q
} W- s* ^- [, h, H
return sel;
7 u5 p: H3 d1 ?( _7 L ]; f- O! o }
6 C4 k+ A$ f5 ]% l1 o+ {0 u' C" C" L8 T; B
public static Selector getSelector(Object obj, String method) {
9 P* A" Q ?( g' L: \ n Selector sel;
; t7 y G0 V7 \+ ?3 Z+ N; Y% O$ l try {
6 u0 k$ V/ J" Q% r7 C5 w; r- T sel = new Selector(obj.getClass(), method, false);
+ [/ w- N. i0 f7 q k+ J; z4 v$ X } catch (Exception e) {
4 T5 ~/ r: \" g/ } }( ?/ W System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: Q2 X0 J6 i1 z4 P + (obj.getClass()).getName() + ".");( |% T1 g$ W% d1 t
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 S/ c& N7 Y2 p, C System.err.println("The process will be terminated.");
( z) ?. H' y7 p8 a. p% ?" {* d System.exit(1);
5 U# h; R7 H4 v3 } return null;. D9 p2 {/ J. K# a0 k2 r
}3 K, Q& X; r8 y2 m' {4 q
return sel;7 N: {5 \" Q- a# U$ w
}3 u% q. R9 d; j1 e
} |