import swarm.Selector;
9 g& Z1 y1 L& E! N6 r4 R1 H* N: T7 R, @ b
public class SwarmUtils {0 Q# d. p) z9 p6 K# [3 M3 V4 X- n
public static Selector getSelector(String name, String method) {$ P0 {( I" |( }4 `. b" ]
Selector sel;& @ Y& H" e. s9 G& i* k6 n4 k& ~
try {
2 _% {3 a( X; R1 |# h$ q" x sel = new Selector(Class.forName(name), method, false);
0 d, T# L* ]: p' N4 w1 E } catch (Exception e) {
1 X% o; I( g- z g0 h* O1 p0 T System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; |# r9 e w; x. U, [
System.err.println(name + "." + method + " returns " + e.getMessage());
. \/ Z x8 e' J( J3 ?' x7 F2 S$ T System.err.println("The process will be terminated.");
* ]& r2 }( ?1 ~: M5 Q System.exit(1); C8 E, G. b6 |, H: C$ b
return null;
( w* `6 v" o h/ z6 f# Q; a9 J }
6 M) V6 ]6 l; U% c- Q& x return sel;
; u9 }- q+ e$ ~, e }( k; y# X# ?$ h, B& L9 ?
: G. q) G7 o8 _+ L, A$ Z% B0 Z, B
public static Selector getSelector(Object obj, String method) {; t7 q) s+ }! G
Selector sel;5 l* ^* W/ k: M, M! F
try {
# ^, n0 H& R$ T; M7 _ sel = new Selector(obj.getClass(), method, false);/ e; B: C" x( g' w5 D8 I
} catch (Exception e) {
& Y$ s/ e/ M7 g5 W9 R* U9 V; I System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "6 s- @5 t) J- [) @' b; _6 K
+ (obj.getClass()).getName() + ".");
7 C9 H1 R6 W% [8 g% C* } System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 N2 _' | I* ~5 g: |6 _4 s System.err.println("The process will be terminated.");
6 W% Q3 C/ q- X7 U r/ J& S, H System.exit(1);' `! B3 o$ V! I% a! S$ [
return null;( {+ g7 J# R; E' Q3 I5 ]
}. F/ s$ A0 Y1 F
return sel;
+ u4 j1 V. O. ]3 [! Y( v }
% P9 t/ l+ U! x* o5 F} |