import swarm.Selector;! \5 c+ W6 T6 S
; Z& P7 m1 B+ A5 C- E' t* |
public class SwarmUtils {
+ W8 C) X) b2 S public static Selector getSelector(String name, String method) {
3 m0 x1 c3 H& a$ o L: c7 \ Selector sel;
# {1 G- N& K; i- R% t! u) B* d try {+ E6 W8 V. P) c+ E. o9 L* F
sel = new Selector(Class.forName(name), method, false);5 G0 m8 k5 w7 e8 z
} catch (Exception e) {- K8 K) _# Y" b
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 a% A% U) D. q$ |8 i" k System.err.println(name + "." + method + " returns " + e.getMessage());6 P! E0 l* E/ s4 f5 f
System.err.println("The process will be terminated.");! C" Q1 D2 w) c1 ]+ q) \
System.exit(1);2 @5 D, b5 l- v9 j. z l; |4 s
return null;8 o' g5 Y9 Y. \& q8 U6 e
}2 f& y2 d' z0 b# l8 ` u( A0 O) f! h
return sel;
3 S7 _; N _$ `7 a/ H5 S }
/ B; G4 d2 ]$ Z# p2 R
9 B4 E/ d1 B2 O9 i public static Selector getSelector(Object obj, String method) {8 |, T8 {& ^- ]% \( m! A; Z5 t
Selector sel;
# i0 [$ H+ S# k8 B try {1 ?3 ^9 W1 m$ g1 L
sel = new Selector(obj.getClass(), method, false);
; Y) I$ u' K0 {3 N5 I# o } catch (Exception e) {0 U0 T' Z+ d' Q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 X& u# f3 L0 |3 Q + (obj.getClass()).getName() + ".");
6 C3 I7 |6 P) I2 \: A9 P$ ? System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, d) q" E& ^, q- q- t6 T% k
System.err.println("The process will be terminated."); S- \$ v: C; `! C
System.exit(1);( b9 H) i6 c& M; h& ^, ]
return null;' d( j* m' Q# H4 R6 Q
}) H6 x6 X) A5 C0 C3 k5 q- h5 |
return sel;
) w* C; k, P- T$ F7 l }+ I* a) k. _; x, W+ E
} |