import swarm.Selector;; c3 e( e$ M6 h) \1 p, A
# S* f3 e% W3 S4 `5 t% h, k" `
public class SwarmUtils {
9 V$ C- b. R2 V2 m r/ w" n public static Selector getSelector(String name, String method) {- z- \8 ?$ Y& D
Selector sel;( B f) E/ x v. t5 \
try {7 q' S, ^) V) Q) j7 J1 _* h
sel = new Selector(Class.forName(name), method, false);
! a; N8 v# T- E/ Q } catch (Exception e) {
: ?( k& y, a3 e t; A9 n: V4 I8 l$ v System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* W: U/ ]9 T" G2 D2 h' [& c" s
System.err.println(name + "." + method + " returns " + e.getMessage());
2 Y; x; [+ f; x7 q8 T, A& ?& ?2 N System.err.println("The process will be terminated.");, b4 ~: u9 h! f3 d( e
System.exit(1);
( z: V3 R7 j" J6 j$ Y, o: m return null;9 U8 [0 a9 G6 q' w
}) G5 J2 k8 @: x! _3 {
return sel;" q& A) t2 ~4 |$ S% y' Z; g
}+ P) M! }2 q# W4 H3 M
4 z9 O" z$ S0 Q( L6 Y5 C' p' g
public static Selector getSelector(Object obj, String method) {$ n8 m9 s0 v' H$ s
Selector sel;
7 G7 J! V$ {4 B3 f' x$ P try {
- t1 n5 A: h5 x sel = new Selector(obj.getClass(), method, false);& y' A0 K$ Y$ @& V
} catch (Exception e) {+ N! |- P% z5 f) t/ D3 Z* ?4 |
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ f3 y9 g+ q! F4 R
+ (obj.getClass()).getName() + ".");
7 a, x: a! Z8 Y1 F( {- R5 a System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, l: l. c& _& j& p
System.err.println("The process will be terminated.");
+ s) P0 v9 I2 n1 B System.exit(1);6 o7 a# b7 o( l4 F+ E' g0 ?" j) a
return null;
3 v, x6 @9 p) n/ ?$ x5 G" y! t5 }; E }0 R8 D, b! |% k# F! W
return sel;& X% |- v' n6 H' l, V7 p/ w
}0 d8 h k! W# e! ?3 X
} |