import swarm.Selector;& w/ O# e% h8 m; {" }. E
( U% F# `: Z, {" ~3 n
public class SwarmUtils {
6 L. I( @* k4 q2 W, `8 Z7 t e9 \ \* @ public static Selector getSelector(String name, String method) {
8 D4 S% v% e% P: ^$ J( e Selector sel;
( x& f/ p( _ R9 \! e7 ~3 r try {6 `; {8 w" V* R" R* G9 U
sel = new Selector(Class.forName(name), method, false);
9 ]4 s3 n. N: b+ _: Z } catch (Exception e) {
+ U9 V0 G4 v! t) C) W System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% _8 q8 e& [9 ` System.err.println(name + "." + method + " returns " + e.getMessage());
: W4 D: q% w! ?3 S2 O- t O8 X" S System.err.println("The process will be terminated.");
9 C) [4 o! C! W Y6 i6 ~ System.exit(1);
0 W4 K5 l7 N, v S return null;
; ?$ c/ N/ [. u" l. u& f }
2 e& W# v9 {) T% F: u return sel;% o- y) S1 X" B8 `) r; _( O3 }
}+ k) _4 ? {+ O+ |: I2 ~" a7 l, D; `
: _" H8 }6 h! K; ~# [0 {. } public static Selector getSelector(Object obj, String method) {
3 ~+ W* h% w% W5 f% F! x/ C Selector sel;, f& F7 `8 g I5 Y- d' I
try {
0 x3 O- b# p7 x" N/ q' }: K0 Q sel = new Selector(obj.getClass(), method, false);
. C) N+ k' E$ A. o- ?8 L5 H } catch (Exception e) {# z0 k: c3 g" z9 R* p B2 _
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 M3 C+ ]0 W9 B
+ (obj.getClass()).getName() + ".");* L: J6 ?& S* O& d9 O+ B
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
& l# [) L6 h4 W U9 C. u& O System.err.println("The process will be terminated.");4 L* ^ v$ L' d4 X# Q$ z( c; e
System.exit(1);
5 d9 r+ C6 l5 w( ]) F5 i return null;
- j. Y9 o+ q, G }
! s' M' a# F. h" }2 z( N% N return sel;7 d. ~# }! i2 n/ o2 I; E& x0 K e
}
4 L5 X0 x0 l f# @! r# p( b; F} |