import swarm.Selector;
% X' w# T6 |! {% L+ y \: G) y( V2 T) E9 H# Y# b6 w
public class SwarmUtils {7 v/ q; l5 X: n* p' F
public static Selector getSelector(String name, String method) {
9 g u, N: m8 F/ N Selector sel;
) M0 {! A( H$ d5 H- O5 s try {
' c! t3 q# E) v7 a sel = new Selector(Class.forName(name), method, false);$ J8 C1 D" X3 A. v
} catch (Exception e) {
K. \5 \, c- r System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 b n! g( }+ E3 m
System.err.println(name + "." + method + " returns " + e.getMessage());- l% J: [3 @& N0 {. H$ C: }
System.err.println("The process will be terminated.");, @; y7 U6 E6 `7 t4 A
System.exit(1);
" {) t' `/ D5 G return null;
+ W: I4 d6 W4 B5 f: a7 ~ }
1 s( Z% ^- ^' _: U, T* R+ y! r& k return sel;2 b# {0 K+ L2 G0 {9 ~
}5 V/ Y5 N% M7 _, z
: z3 R1 J+ S5 \* | public static Selector getSelector(Object obj, String method) {
/ q* J0 C# y- S5 k Selector sel;
( ^) i# Z4 o4 R$ C( D try {
: O8 _; J3 z# \1 G+ W8 H( U sel = new Selector(obj.getClass(), method, false);
6 q0 F# ?+ h2 O! J# h, |- x } catch (Exception e) {8 R \% l( d3 f$ R1 H
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 I. @& _. H% e4 B: `
+ (obj.getClass()).getName() + ".");
7 p' ~- o+ ^5 z2 R: v0 `0 r1 Z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());3 T6 A" T+ l1 P2 d2 _9 ^0 s
System.err.println("The process will be terminated.");$ C+ m* h0 u* g% [2 L
System.exit(1);, h: D, t* A/ c$ d0 _% d. p$ i% @
return null;
' y4 C A8 j. N0 K }
& g& b/ ~5 _, V return sel;; x% W5 H% m1 X" C- H. |
}
* }, ]- w2 R& ^8 A* h2 @5 R} |