import swarm.Selector;. v3 m y6 j0 e1 ^% I2 ]+ }# h
) V: `5 u) h% y: s7 V
public class SwarmUtils {
% Q1 x( _& s% R7 |2 H+ m public static Selector getSelector(String name, String method) {. G3 ^6 O' i5 l$ [$ ~9 ~ [- l
Selector sel;! j- c# R' z4 _6 D6 ]/ M- V
try {. W1 a( f; T0 }% a5 P5 |
sel = new Selector(Class.forName(name), method, false);
. M# S. d% D" } R } catch (Exception e) {
1 i5 [. _+ X1 f! g' V System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 e* i) J0 ~ W0 ?2 G! b+ Y- A System.err.println(name + "." + method + " returns " + e.getMessage());
: q/ m; w7 F* M m$ Y4 c System.err.println("The process will be terminated.");% G: v5 I. _7 b: ?- s
System.exit(1);( o$ u0 b1 X3 o+ R$ T: M% I
return null;
1 b; I' j/ g+ ^6 I! q }! T3 Z0 g: J2 Z' O0 p. y2 c
return sel;- \% C a- ^9 h& C5 o
}
* D* _+ E U' \' j" M3 n8 V' n! r6 l2 y% ]1 r9 h
public static Selector getSelector(Object obj, String method) {
% l0 Y0 O6 X- M4 V% \: R+ P! O Selector sel;! u8 y9 L! r u
try {1 F- W/ o. m0 N- s z: i
sel = new Selector(obj.getClass(), method, false); H& l3 ]3 E0 ]( o+ y8 Q d
} catch (Exception e) {
3 }4 t7 R; V5 T8 { System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
; z3 ]# b$ e5 K+ O" n. Q2 s + (obj.getClass()).getName() + ".");' F; F0 c+ L# F- ~/ O
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ l+ k& n6 t) J System.err.println("The process will be terminated.");& }& C+ H; v% r, P
System.exit(1);* S4 ]4 P; ^) P
return null;
1 h! {# }/ T$ m }
; P7 ~: _. W# @) R K0 a* h return sel;
" v; m' n) \& ^0 J2 {3 ]5 [$ B }
1 B6 L$ a# j7 a2 O/ |1 V# k L} |