import swarm.Selector;
" c( m' J0 ^$ r H& g2 A [" l: Q6 ~
public class SwarmUtils {
) b; A% }) k6 H6 n% w" {/ q public static Selector getSelector(String name, String method) {
7 p# v) ^0 m% E# o0 E9 l Selector sel;
( |! g |4 N, ~0 |1 K+ |- x try {1 b0 s3 o0 T% W; c+ g5 g
sel = new Selector(Class.forName(name), method, false);) }3 F2 K+ U: G: W# r
} catch (Exception e) {6 @" y+ k3 R, i! B# U/ D0 a
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( O8 l7 _/ ~& ?! H( b% v4 H) ? System.err.println(name + "." + method + " returns " + e.getMessage());
4 i( E0 u. \& ^1 U7 q6 k System.err.println("The process will be terminated.");8 @: B7 @0 E, v7 Q p0 [1 t
System.exit(1);. h- c4 i1 |. D6 Q! q
return null;
1 @" j( ?1 G0 {+ a }
1 F& X! c* X# f- j- r. m return sel;
% Q$ V& N; K. Q# |/ x. K& r7 F }
4 t( d% f: E4 [' n/ ?- x, n. w0 W- f4 n" ?# O) [) y6 n
public static Selector getSelector(Object obj, String method) {
* u+ U. v/ ^( {: e1 ?% c& U Selector sel;
; v. K2 P8 Q9 N3 E( X try {% |' @2 R4 `# n3 ]9 A; a( w8 ?: x7 ~& n O
sel = new Selector(obj.getClass(), method, false);
* ? w' u2 ^& {6 D } catch (Exception e) {* `5 I/ d8 o& a2 {. Q0 G
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 r1 S( V Y7 C* }% ]4 P+ T# V4 a
+ (obj.getClass()).getName() + ".");
) E6 O* f; @$ J9 w, a. W9 V6 t System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 Y( j3 u/ O% X$ Z8 w+ \
System.err.println("The process will be terminated.");
9 O" o! u+ ?0 t$ F& y1 ^ System.exit(1);0 i/ a1 y& D# {$ K: b) F
return null;
+ P* [3 _% e7 E8 v% A0 S4 t6 \ }1 v$ `/ G8 L9 N" c: A
return sel;' O+ h( w6 o( {' f! s
}
6 J* g* M- z, L$ g- l} |