import swarm.Selector;
l' v8 \9 C+ V" F- J+ l4 h2 D- L$ q/ J& }2 }0 l, L
public class SwarmUtils {/ I% ^" ~& G- b* ~
public static Selector getSelector(String name, String method) {
8 x x3 F; d: n. i, M Selector sel;
* {6 f! Z& H& M" _( Y try {$ w9 D- V. r4 X' \" a
sel = new Selector(Class.forName(name), method, false);
6 h, I8 h0 J2 j! ^; W1 _ } catch (Exception e) {
/ M6 i1 g) O" D, R: P6 H System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");! C/ f0 N/ F. r) R3 _* q' x- w
System.err.println(name + "." + method + " returns " + e.getMessage());
4 [8 n1 g* ~7 K) v$ g" }9 s) A System.err.println("The process will be terminated.");% `" C( e7 w" r- u5 q
System.exit(1);3 A% r% r3 f Z u1 L. I
return null;
1 K, K" r$ l# r" ~8 c$ R* ] }
) p8 H; k- K& a1 n, A+ i return sel;/ N# Z& G! P7 v' {+ u0 c5 \4 F
}% D9 s0 }- ^* m3 ]
: V0 s$ r) O1 `. y
public static Selector getSelector(Object obj, String method) {
2 C2 f0 m. q* y. c9 J Selector sel;
6 O1 \: w$ b2 j, T# C try {
: w" @: [: u: _- z+ V* E sel = new Selector(obj.getClass(), method, false);1 T1 Z8 P3 {' L F: i) h
} catch (Exception e) {- V; O- A: u8 }+ O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " q0 m, t9 J! u2 ] b8 ]6 |
+ (obj.getClass()).getName() + ".");# {+ Q" m6 ^$ |0 H; e7 n, ~
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, N' U/ S6 v' i& C System.err.println("The process will be terminated.");
: F8 m+ `! r# l* Y System.exit(1);6 p( B( ]1 V% n |5 D$ e# H
return null;
; M: E- G; y8 U# I+ Z/ c }1 \2 p4 L" u( M |4 H
return sel;
5 L& @ R' o6 l/ L4 \' q }
0 |# x+ o8 Y9 q; w- _: P% e( |2 t} |