import swarm.Selector;
j- J2 s; N b% {. f3 ^% B% g: ~4 b( d& z# |
public class SwarmUtils {; G8 c3 q9 ]: r4 v# b
public static Selector getSelector(String name, String method) {1 X q5 Q, V/ X8 x
Selector sel;0 G3 R* ~, l* S! u
try {( R7 v' x3 K+ h& }1 e/ k
sel = new Selector(Class.forName(name), method, false);
: L. a. X9 X- g0 ?1 l5 a5 K' M# j } catch (Exception e) {
- g3 x- _& u; Y6 d" s! M- r System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");% U" n/ j6 }- l- l% m& a
System.err.println(name + "." + method + " returns " + e.getMessage());" l2 a# E/ C: }/ d) S, @
System.err.println("The process will be terminated.");
?8 d1 [0 m/ V9 ^9 ] System.exit(1);
8 D0 u/ R" [3 ~7 K( J- d- d return null;, W) m! C% I9 l5 ?, n
}
: W) ]: {; X! z( t9 P return sel;: E$ h1 g6 J. x
}7 I, s y1 E) {# H, |
9 }. s* C- T4 q" \( ^9 o public static Selector getSelector(Object obj, String method) {
f- N& T1 Y/ ?& x/ z2 J Selector sel;
) l3 r7 Q+ t4 F% L# r6 v/ L3 z/ w try {
3 k) t1 z7 M, ]! m2 U sel = new Selector(obj.getClass(), method, false);
! v/ _6 O( u6 Q" U) W( W t. K } catch (Exception e) {
( \; j5 `9 t& o; b' N7 c System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- F6 J8 e" q w6 v( p + (obj.getClass()).getName() + ".");
( Z# D2 _: d+ s8 c: Q System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( S2 A- t4 z0 [7 J System.err.println("The process will be terminated.");
! ]" N. V G: f+ X System.exit(1);! k- ~' S$ _. ~$ K$ o- r
return null;9 h0 V4 F2 z3 C! V+ J
}3 f8 a4 x8 e$ V) W1 s5 q2 K
return sel;; y- V6 M7 F8 R3 {; A: W
}
8 l4 D6 H3 l3 y* Y: R} |