import swarm.Selector;$ K" h' M. b+ _$ W) w; J
/ f" F6 r% T! g& b# q% H: ypublic class SwarmUtils {) W1 V' a: g: d: I- {
public static Selector getSelector(String name, String method) {9 _% o9 r5 }5 f, J
Selector sel;
4 t; }, y2 T2 [' o) ]5 W try {+ M; ]' e; D$ A
sel = new Selector(Class.forName(name), method, false);
- P# b5 G9 C! I% m+ @ j: h } catch (Exception e) {
" y8 m$ q% m7 H( a( H, U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) D: ~; ]5 k& [% t" z1 i: \! s System.err.println(name + "." + method + " returns " + e.getMessage());
0 n9 Z. h) x5 \* V System.err.println("The process will be terminated.");
- s! ]; ` q7 O) j! o System.exit(1);
9 }$ o& O4 ~" z9 L. W2 g% e- d return null;
/ F+ c% p# h% d! y- b }# C" j) d+ l' E5 D
return sel;% v1 e6 z4 i g1 c+ G
}. l% J X3 X2 ]/ }
* Q6 O( s* Z s
public static Selector getSelector(Object obj, String method) {. N' H& B% c: j# Y, {, ^4 H" T
Selector sel;8 @* a A3 \ C0 z; H
try {
( O2 l4 S7 R# I D" d sel = new Selector(obj.getClass(), method, false);
7 ~- G' n3 U, {6 l. n: T } catch (Exception e) {
+ U* j5 K0 ~: Q2 m2 J& p3 f3 y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' \. p2 Q8 k3 V' g7 X3 P + (obj.getClass()).getName() + ".");2 [1 G# t* r4 U1 L
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 r; Y3 l. C3 u7 j" [ System.err.println("The process will be terminated."); e# f! a) r e1 R% v
System.exit(1);
@% V" L+ q# ~+ R- P4 j8 q return null;% v5 S) V5 D2 `9 w- q# w* Z
}
k% N, I9 Z) m( x: {% ~ return sel;8 I; K. y" c0 b# X" {
}) A( n. D3 _( X0 K. H- g
} |