import swarm.Selector;5 V& m! l2 [# c! x& o: B
/ ~' \- @! g. Q8 R
public class SwarmUtils {# @: s6 _! o% z# R5 L; z
public static Selector getSelector(String name, String method) {
5 a, E. y$ V' D4 _/ E Selector sel;
) @7 O, J1 j& K- R, v/ X try {
$ E: P0 V! A+ q sel = new Selector(Class.forName(name), method, false);/ ~/ f4 V: U* |- B, U8 F' r
} catch (Exception e) {
3 G( h4 {" x6 ^1 r' p4 d$ A' i; _ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' ]0 L c! r: r% T1 C, d3 ~ System.err.println(name + "." + method + " returns " + e.getMessage());/ B3 w" }7 C1 ^* k5 T6 M/ W! T9 X
System.err.println("The process will be terminated.");1 U: Q( h0 q; E$ U) O
System.exit(1);
0 u1 p& d/ `- x; F3 S% | return null;( [& q7 v5 h. x. p1 R% }1 \5 P
}
9 [+ v) U0 a& l8 p% V: X return sel;/ i8 L% A1 E% L/ A3 V
}! I5 ?8 y8 @) k9 y- g; k
; E5 r' `0 W" z Y9 N# O public static Selector getSelector(Object obj, String method) {1 E% t& r- n/ {# N/ B4 h
Selector sel;# D& c% C+ l6 X! R& {4 i& K
try {
4 x' [4 d0 Q' t. I, } sel = new Selector(obj.getClass(), method, false);+ e8 Q3 @1 c' g2 u" g H; B
} catch (Exception e) {3 t1 ^* T+ c+ U' @0 k
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "7 X) U7 ^2 V& s2 N( p) S
+ (obj.getClass()).getName() + ".");/ X+ p- a$ A6 T
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, {+ o' f; A- z: k L0 m0 m
System.err.println("The process will be terminated.");
- [% [4 }" k. o( z) _5 A System.exit(1); o3 C" X+ P b1 N& |
return null;
/ g; ~$ k i6 c }% J( T% B0 G: y# v4 K& H5 Q8 ?# b$ V
return sel;. P* u( j) o) W
}; S* v q1 p( D* E/ r8 I
} |