import swarm.Selector;
$ A9 a7 F' T) Z. }2 e2 D, ~- @0 v+ S5 Y" T- W- z1 K
public class SwarmUtils {) I$ a) R! u; W9 U4 q
public static Selector getSelector(String name, String method) {
1 O2 O3 u9 o6 l0 Z4 F# m; }/ P Selector sel;
c* ~* F0 t+ g5 {1 c9 @) Q% h try {
7 j% F0 n1 r0 ~1 p# d' W4 S8 m sel = new Selector(Class.forName(name), method, false);
! O) ]0 A3 W& u } catch (Exception e) {) i8 |7 `: K1 W& d( V" h; B: ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");, y1 g @% Q$ ]* M) m# N
System.err.println(name + "." + method + " returns " + e.getMessage());: r, p- b9 H) f
System.err.println("The process will be terminated.");8 h0 p% g: |. P8 R' V
System.exit(1);! g7 T7 @" B1 ` u; D2 v
return null;0 c4 |+ Z! n; ]1 W! P
}) i6 I# _8 ?$ }0 @1 K
return sel;; S: T" k7 F% H7 }+ I
}) ]5 s( z+ |$ e- A: F& O3 C, \+ J
- Q2 ?& r7 X: I& ?3 U8 n6 U8 @" I
public static Selector getSelector(Object obj, String method) {
4 P& L# Z% V' H9 i& b+ e2 z Selector sel;8 Z* k+ Y" R* W, u1 t& w
try {
! m2 j( v3 C+ ^- G. U; ~7 p sel = new Selector(obj.getClass(), method, false);& R) ?* x3 T3 ]8 q
} catch (Exception e) {! J ~+ O9 e6 G7 |7 p
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( B; E+ a c- X7 V0 `1 n + (obj.getClass()).getName() + ".");
$ u4 w' L8 n7 Z# p# V System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 V, i3 Y! h, Q. x: Y/ [% Q# @ System.err.println("The process will be terminated.");
& ^1 {) X, F; h- b$ e- I! s2 Z+ c System.exit(1);7 v6 r0 _: Q" V* ?" `! w: \0 {
return null;
* A, y# K% p6 R }
m7 B. M- s8 f$ d5 ~, P9 z0 K return sel;
7 K* L0 a" m7 X# G# n }: W' z1 n1 r: B" ?- a$ J1 s
} |