import swarm.Selector;8 U- A! l6 {- N; g l
/ o8 v* K" I' L6 _ S4 V) ^! G: C
public class SwarmUtils {! ]! R: i6 Y/ A7 x4 v
public static Selector getSelector(String name, String method) {+ P- V J+ x+ k& q/ X( J3 G
Selector sel;; U( u3 @3 l! v' e+ Z' c- J) W/ n
try {
- O; U* Q, W, ~ sel = new Selector(Class.forName(name), method, false);
, V$ n# }4 I2 |7 V0 D( w } catch (Exception e) {
7 k" Q2 n* k5 H8 T( B; Q- k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; y* }9 T! M1 F" p5 x7 ` System.err.println(name + "." + method + " returns " + e.getMessage());0 w* t! V3 |: w# {( f
System.err.println("The process will be terminated.");
% q' G+ B" _& Q; J$ K+ J System.exit(1);4 m0 m; d3 g3 ^' A
return null;& K/ X" A+ F% c1 W8 ?+ k1 e3 h
}
z' F9 b3 ?2 d- N9 M return sel;, {/ r0 V+ f+ ]0 m5 Z
}' z7 \8 w, L7 a+ _9 S- a
( m: m" ~5 m t" }# E
public static Selector getSelector(Object obj, String method) {
. _+ I% h9 Q+ p0 Y. } Selector sel;
9 u7 e" ?9 o' ?7 [0 O& C: | try {
( g" o* s5 M l7 C2 | sel = new Selector(obj.getClass(), method, false);; D( K! O$ L. t: d7 r$ x# m
} catch (Exception e) {& X" x* }" e* ?' W/ k6 n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ Y, ?7 A! U6 ?2 e& t, w" N5 d8 [
+ (obj.getClass()).getName() + ".");
7 }: e8 v* S2 J4 F7 [$ b6 B System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 Q& Y. K2 ^/ F# R4 v7 j System.err.println("The process will be terminated.");; y. @+ c) c- [1 H# H& h
System.exit(1);
' ^' P! u8 D( ` return null;
: ?6 ^+ s1 O, J# I) k }2 k8 I) E$ a/ R+ ~9 p
return sel;9 X+ z" H! D; X; }6 k1 i; g
}5 @6 o. `) ]8 g& j, A5 L
} |