import swarm.Selector; N. _: F" x% v. e5 i U
. q4 t& t9 m. N/ O5 a: I2 i
public class SwarmUtils {
/ ?4 @/ X! U! Y. X6 C$ u public static Selector getSelector(String name, String method) {
! G. X! `1 [* b Selector sel;
% O1 @! |/ w+ i0 E6 U try {1 B4 I6 G, Y3 U& S) l$ ~
sel = new Selector(Class.forName(name), method, false);
5 C! t( b7 c$ t- h8 u) j- Y } catch (Exception e) {$ ~" @# |3 q! t3 Z i) q/ ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 W8 }5 B& r$ \+ a5 O) x9 }4 j System.err.println(name + "." + method + " returns " + e.getMessage());
' b( ~% S+ j$ ]# d" J2 K! u1 Z System.err.println("The process will be terminated.");
1 y3 x' x& C1 q9 \- x System.exit(1);
5 Q C" f- g O# A# j6 n return null;
6 E9 Y, @6 E" C4 o& h+ O }2 e* e& _) T( v. t7 b L" C
return sel;
' B0 k# R" ~! }5 ?8 ^2 D* L }
2 ~3 G' u* `1 C# Z$ i7 y
$ y6 H+ A9 M- d h' [# ` public static Selector getSelector(Object obj, String method) {
& |; k( R& @5 H1 c( F) e' o% Q Selector sel;2 z" Z! C) C: V' Q# {# f
try {
: p- b& {3 T$ l' X' b- ?2 L sel = new Selector(obj.getClass(), method, false);
* p& W5 o2 s$ {# x, W" t1 l } catch (Exception e) {
: O& {- M8 W7 R# m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' M5 B, a/ M9 Q2 K# {9 c + (obj.getClass()).getName() + ".");
5 _& @( K* L& P. d6 V* f System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% f* Y2 w- W k. \
System.err.println("The process will be terminated."); M2 Y M# y7 J" f- r0 P& c8 K
System.exit(1);
3 h q z& u' ?! k+ M$ |( Q( O return null;
3 ?2 d5 k4 P# D0 e# W% P$ P }
9 Y/ Z" Q' G) E7 ?9 \ return sel;6 G- ^) o* K# t! K* {0 S8 l/ b
}1 F( A3 C4 H: _# }; `4 _/ F
} |