import swarm.Selector;4 D2 h3 w/ i- y# J7 a" P7 s
: k8 ~! ]# k: [3 S# O" s$ T+ t
public class SwarmUtils {
3 f. \/ K0 }$ ~! @5 U; G! X6 H public static Selector getSelector(String name, String method) {
1 }' G% @, }+ C. i7 Q Selector sel;, [5 N, V) i5 I/ ]. _; c
try {1 Z* i v6 X# k$ L: s1 c
sel = new Selector(Class.forName(name), method, false);
) ]4 U$ o0 S$ q8 o8 G' ~7 n } catch (Exception e) {, ~: f5 d7 W) G: p
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; {& _) {4 P- m: w, A System.err.println(name + "." + method + " returns " + e.getMessage());7 q! h" Z+ v$ ]6 p4 L
System.err.println("The process will be terminated.");
3 [; r4 i+ ^& {; h* x3 [ System.exit(1);6 t9 n' e2 m4 Z, P- X% u1 u0 f; k
return null;/ j% e( U6 I! K" I; H2 X5 c
}" c+ Y" C0 z3 s0 o
return sel;& p6 X0 Y; T0 w% G
}; a! E3 A) i R# t* j6 J
1 [0 d# [$ B4 t! P" y public static Selector getSelector(Object obj, String method) {
5 |2 m1 t+ v) S+ e3 k Selector sel;
1 \% S. p8 r \ try {
; @3 |' p, T/ w8 e8 M$ U sel = new Selector(obj.getClass(), method, false);
% Q8 F! K. f+ G% D } catch (Exception e) {! C' L; |' n Z. L S6 V9 r
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "0 S+ h& u" O$ w/ r3 t
+ (obj.getClass()).getName() + ".");
: @' o) L+ r: g! B3 r/ h System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' k3 r9 @ p- h$ p/ h System.err.println("The process will be terminated.");8 j) i% v# V0 h1 L& J) Q
System.exit(1);
+ s A3 y( U7 M& r( K# n; y return null;
1 W6 }+ C, h5 `5 o9 O5 { }
/ F- \8 Y1 \; o1 j' P4 Q8 Z6 H return sel;
( ~/ c' _. n5 ]: z }
( A6 c! c; f2 O. P) W/ \} |