import swarm.Selector;
' y$ J# k; l7 t' V% }; j) T3 b" {7 K! T, g! I7 G. h7 u" e/ i2 C
public class SwarmUtils {+ e) Z7 b4 V7 ] e$ |
public static Selector getSelector(String name, String method) {; n! `: a- k) U3 q1 y& n
Selector sel;( R7 a$ d5 i5 [0 c% ~8 A. S
try {
5 t- m! Y: o& s, \ sel = new Selector(Class.forName(name), method, false);4 A6 S- k( F: k, s
} catch (Exception e) {
1 \% l- u+ Z5 L, X$ z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");1 Z0 ~1 f: ]1 v2 c0 x
System.err.println(name + "." + method + " returns " + e.getMessage());
4 U; Y3 a- G* v System.err.println("The process will be terminated.");# I6 h; f3 a* P4 z5 B0 P( G D9 y
System.exit(1);
. T5 E+ ?$ i' w( O& M return null;5 p7 Y) Y9 u2 \. I
}
+ C# K2 q, @& L# T2 i return sel;0 p7 O6 n' l$ R
}2 p$ d( o9 q: r, ^
A0 B% Z# R+ L3 n. A. ~& [3 l public static Selector getSelector(Object obj, String method) {
5 h& x; Z- `9 H Selector sel;
1 ?' Q1 I7 D- p try {% r! S9 x/ F7 N6 |' {* d8 l
sel = new Selector(obj.getClass(), method, false);
: E3 P* O2 Z" D0 W* {: q } catch (Exception e) {
7 ?' G0 x0 V2 L; _0 U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", T* x9 o" D/ ]% s
+ (obj.getClass()).getName() + ".");2 s- @8 x% F" x, a8 w: _% i% {* n% W
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' |9 F, X( q4 Q4 B+ z% E System.err.println("The process will be terminated.");
# H! d$ e2 ~6 K* V3 S% S0 J: L System.exit(1);3 Q2 @4 e$ l; {7 u
return null;
- p0 P. f. |: z4 n; G- K }
1 F% e9 z' d `8 p. x* Q$ R return sel;4 y: a; z c1 T2 A2 v
}6 p7 \9 x+ v+ B' Y! m
} |