import swarm.Selector;: J6 U$ W5 ~7 P/ m T- O
( {6 Z7 x- y6 v5 G# v) q7 h \
public class SwarmUtils {+ ~0 d+ s/ i1 }3 y
public static Selector getSelector(String name, String method) {
. z& ^1 F" P% U, x$ E) F9 m Selector sel;2 K& e C5 @: f k" n# N+ h3 T
try {
) Q: G7 D) j8 Q; R5 Q, ` U9 K sel = new Selector(Class.forName(name), method, false);8 W: a5 b* S. f, k
} catch (Exception e) {
; ]2 v) u; u7 F! q: X% [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 ~8 X5 H+ V* u
System.err.println(name + "." + method + " returns " + e.getMessage());! j& \2 R& z, U5 w f
System.err.println("The process will be terminated.");
. L$ ~/ H z" G System.exit(1);" D6 B# f. n2 }( |7 f0 R7 z' Q
return null;
" H% P& I2 L! j. L } m5 N' U; H" R$ i
return sel;3 x- X8 g" n' [5 [1 [2 {
}
4 |* N/ f7 n( X0 N8 ?1 q8 h5 B5 E* x) X6 N4 v$ q# K! v$ V9 X3 W. B
public static Selector getSelector(Object obj, String method) {6 H- z o+ ^/ d3 L
Selector sel;
; ?0 ~3 v8 @0 @' y try {. W5 k5 c9 {5 k5 Q5 `+ R8 l, Z
sel = new Selector(obj.getClass(), method, false);
5 r6 Z: @# S; f% [- T } catch (Exception e) {. p$ F+ @7 o8 g% P
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 \+ b, B( ~( O+ d5 w; B + (obj.getClass()).getName() + ".");
* H$ n4 P& m8 C6 _9 G System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
3 w: U5 R( }! @7 K9 ^ System.err.println("The process will be terminated.");
% W3 @* i! |/ `/ j3 p System.exit(1);( s2 Q. H4 v+ S2 `2 X
return null;
9 j2 I/ N& y: Q4 T }( K* v. A+ O6 T1 }
return sel;
2 `9 l) i# Q6 c. v; W" T) | }8 u8 D) U D E0 H$ Z! m$ L
} |