import swarm.Selector;6 `9 c8 n" o* G
. B' b0 F2 N5 ~& u; t% c$ W8 l7 D
public class SwarmUtils {' F! j* T3 G. G) E S! `
public static Selector getSelector(String name, String method) {
. k! y0 M& H& j; {. e0 E- p Selector sel;& F% J! D7 u- H7 k& |% V
try {
# ]& H# \5 r9 j sel = new Selector(Class.forName(name), method, false);1 ]" Z& m! r. B6 N3 x
} catch (Exception e) {
# K# [* w+ d; S0 k0 o" J# o: [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ k& g2 j7 a2 G5 r System.err.println(name + "." + method + " returns " + e.getMessage());
+ a4 n# j# V: A! | System.err.println("The process will be terminated.");
( p% p( G7 m9 H# R- y System.exit(1);
( A2 v% k. F, M! C return null;
, L" y) Z9 R$ Q f: q/ U }- o2 `$ Z. L: ^9 m& S9 i F
return sel;
, @3 _- i( [% T& s6 C }* {2 P% P3 _7 E
% p" B/ C4 S5 p9 m9 L public static Selector getSelector(Object obj, String method) {
' X) k2 F( I2 a. u* b Selector sel;2 {/ U( K; {. i( u" d5 e
try {
, ?: Y1 k5 m6 ^8 U$ p1 O sel = new Selector(obj.getClass(), method, false);9 g: T7 k/ \ m% U
} catch (Exception e) {. F$ _" Y& \5 u# z7 g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. }" r1 J0 L& Y + (obj.getClass()).getName() + ".");! G7 G/ c+ W8 W' a$ Y8 c- J0 B
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, G% _2 S |; A* [ System.err.println("The process will be terminated.");& e) J k0 S* I% |5 j. h
System.exit(1);
! M4 c7 O0 _* A& E: X return null;
; i, R& H5 g( X! z }
+ ^+ C( D9 S7 a; G return sel;' |# F8 M; I! V1 r) U* g% k6 [
}
% R$ ]2 r3 r0 n% S- q" }} |