import swarm.Selector;
% J( i0 N$ n) O3 m* t
& W! Y# c8 Q0 f8 Zpublic class SwarmUtils {' G0 P' `& U' a! T
public static Selector getSelector(String name, String method) {/ C5 c% v* F" u2 a1 d3 ^1 N1 X
Selector sel;
1 ~& u7 S2 r: D8 p0 j9 h try {, ^: _' h' t* k3 \' ?
sel = new Selector(Class.forName(name), method, false);6 l, [+ a2 p9 a
} catch (Exception e) {/ y3 w: `+ } ~3 h& a0 x2 O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 w# _* ]" H8 M+ n& `
System.err.println(name + "." + method + " returns " + e.getMessage());3 w1 T4 d" W' a! F: n# b
System.err.println("The process will be terminated.");
% Q4 V3 |& g% V( {$ f/ j System.exit(1);
~( _" g, a2 \ T. b- L, a return null;
& U) @. @8 P# a) V, \$ F& T }9 r% o2 w+ `7 S- r: B/ {
return sel;
- M: }! C& f% d8 L! X }+ ]% T: }. \$ w! d
* f! W( g# m% x& m% S. G( X
public static Selector getSelector(Object obj, String method) {. d5 e( u5 B- G
Selector sel;) j' ~* P; u6 M8 ~ v
try {6 f; i2 I5 h8 s/ _! y
sel = new Selector(obj.getClass(), method, false);
# g0 F, J6 \4 v# T5 J; I } catch (Exception e) {
* A6 k1 z/ q* m* E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ l3 V5 z0 W2 {& N2 u + (obj.getClass()).getName() + ".");
: [+ n; U- M0 H. s# ?' W System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 a; ^6 e" M8 K4 d& w( _
System.err.println("The process will be terminated.");
& m8 C( W2 e- a" \ System.exit(1);' Q0 m' W7 k6 z8 G
return null;& |9 p) C6 U5 _) ]7 B
}/ Q; s* {- j# G' H4 C
return sel;2 S0 Y" B0 z6 U# I
}
/ b7 D9 L; V C4 m$ M* C) ~; F} |