import swarm.Selector;7 W: s8 l) ^& B: M3 _' i. q
* Q. i# K0 Q6 mpublic class SwarmUtils {! c8 h9 F/ Z7 @7 D( S" ^; m
public static Selector getSelector(String name, String method) {* K/ x8 X/ S* R) Y4 Z+ d3 T* H
Selector sel;
+ s& a4 h! {; m; w3 e try {
/ i7 h/ D7 ~; E, I$ r8 c sel = new Selector(Class.forName(name), method, false);9 l$ v6 \' Z( [; F2 j
} catch (Exception e) {9 S% w# o4 z0 D3 e7 ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) D9 u6 K- X& {. G8 g System.err.println(name + "." + method + " returns " + e.getMessage());
. f$ w4 J8 D/ m( E5 R7 a System.err.println("The process will be terminated.");! R* d6 \: w w' x
System.exit(1);+ B8 t! ~) x8 b5 X2 F. m U( D5 h
return null;; ?' C5 s, ^3 G3 m# n: a
}
6 O7 C1 K8 S+ m% x! }( D return sel;# o$ J' z* d3 L4 o
}6 G4 j$ q e b2 b9 e! F" z, o) y
2 K3 d1 Z" c( D3 F& Q
public static Selector getSelector(Object obj, String method) {% W- V& ]& p1 t" H7 [* e9 X
Selector sel;
5 M" S; M9 p3 g1 F: ?' D9 o try {+ n0 j8 |8 j% z- R7 P0 N
sel = new Selector(obj.getClass(), method, false);
$ \% K4 U! b6 x( F2 D/ F ? } catch (Exception e) {
. @# @: v/ \* Q5 _ z7 o, ?; \ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " N3 i5 P5 o# B
+ (obj.getClass()).getName() + ".");/ ?" h3 r/ Y. P6 o. N/ i
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% s. P$ N* i: |- o: E2 \: V' V System.err.println("The process will be terminated.");
% E o1 o9 L( _9 } System.exit(1);* v# j" D8 d" ]8 W2 Q! G6 B0 e# C
return null;2 p+ N7 }" X+ |! @
}
\' r1 T; K: T5 u3 d* i return sel;2 n) t' \6 p- ~* |( L
}. l" Q7 g- j4 {& e% a# P5 Z
} |