import swarm.Selector;
$ z* D3 v' N( I8 K0 |/ N @6 T3 N) v9 ]* o( Y/ j. g
public class SwarmUtils {, }- J; W$ w# P: n" t
public static Selector getSelector(String name, String method) {
: m7 J$ s0 z# S) e Selector sel;* n K; X5 d; x$ m) K& I
try {
8 w2 u7 N( ^6 ^$ s8 [1 O7 i! l/ a+ @ sel = new Selector(Class.forName(name), method, false);
5 F! e2 S) F: o3 m |4 M' M) q } catch (Exception e) {
4 T7 n* y% w [ D System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; ^, o/ F+ |; G! K4 k4 z System.err.println(name + "." + method + " returns " + e.getMessage());
: a m |+ _3 J, X System.err.println("The process will be terminated.");
2 v: r& n. ]/ H+ y* V/ x0 ]* h System.exit(1);
: H# v7 S _& {& e/ t3 D, G6 H. w return null;
M+ T3 P6 i K0 f3 `$ }8 X }
, g, H! Q$ \* z return sel;5 L9 d0 }1 s1 a/ u7 ~4 g$ L
}
) Y( v2 g# g0 A* B5 X" V. T B+ |7 Z0 b( l# s. L2 b
public static Selector getSelector(Object obj, String method) {
i8 J3 C1 T6 i9 y* P8 h! `* U4 ` Selector sel;' O! h1 M' p# T
try {
0 T) T Y& @, { sel = new Selector(obj.getClass(), method, false);/ q- _( [5 }7 j/ X1 p) s6 Z+ }! {
} catch (Exception e) {
% l% Y8 s7 l2 \! ?; { System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 p3 V" |. p( B! Z
+ (obj.getClass()).getName() + ".");
X6 L. E1 Y' K3 c+ H E0 L System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 Y8 z( n+ d" C" l. r$ H
System.err.println("The process will be terminated.");4 ~8 V7 c1 G+ w7 L4 }
System.exit(1);! X/ s7 }9 _0 n' L q2 x( Z% m+ m
return null;" [, a8 d8 j3 n' @1 v) N9 B
}
( o l% M" w6 Z P/ u+ a return sel;! l! @. H0 \5 _2 i3 @
}- N$ i8 _ y" S0 n" m( f
} |