import swarm.Selector;) T$ K9 J+ m0 t
7 r: g0 s7 s. C# Tpublic class SwarmUtils {6 q4 k8 s4 S' C; G8 i
public static Selector getSelector(String name, String method) {0 S7 }8 _9 O7 I4 H- [
Selector sel;2 l" B( a; H8 O, h/ m
try {
/ v6 h+ C+ v' I; u sel = new Selector(Class.forName(name), method, false);
2 M0 H( }, W1 s/ G } catch (Exception e) {
* g2 J- I$ v; z3 z0 I System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' x8 Y% W W' r7 K8 G" _! r System.err.println(name + "." + method + " returns " + e.getMessage());7 s. W! R" t2 _) C4 r; x9 M* v
System.err.println("The process will be terminated.");
8 k( V t& K2 A* j7 F System.exit(1);
2 h6 k. ~9 {: U- x return null;
4 q1 u- q B" t5 j }: H: t& \8 D+ ]7 I. x+ v9 U
return sel;
- L: ~+ k+ K# a: h6 _4 X' O3 F, e }! y/ v" f7 C3 Z7 q# A u& `2 n
) { n9 V h0 v4 ^ public static Selector getSelector(Object obj, String method) {
. S, m2 L- N& E Selector sel;
6 @$ J6 G5 V2 u try {: p3 q" ?4 [' L, _* W& M
sel = new Selector(obj.getClass(), method, false);
$ t" P! f4 d/ U' [, I } catch (Exception e) {' X9 E" o; \+ {
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ". D8 V" X9 j2 f& t) y
+ (obj.getClass()).getName() + ".");) `* s; `" e8 x9 G
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 l2 V: U- G1 e% a0 h
System.err.println("The process will be terminated.");, T- \* ^0 F, [4 Z
System.exit(1);
& y6 a' U1 m$ p3 Z return null;2 U8 M9 l; z: {" d
}
9 v+ d6 F t. k( a2 p! j/ c return sel;
( u. D) ?6 [, ]& i } {+ r# W2 n+ j3 H+ z6 h# Z
} |