import swarm.Selector;8 a3 l9 w7 F) k* `) S) Z+ F( } E
b9 t! M. ~, W4 p; J' s" a
public class SwarmUtils {
) t0 r" j! O5 v) c) e+ F public static Selector getSelector(String name, String method) {5 f0 M0 ?$ W$ F
Selector sel;
) B& ^* I/ G( I) { try {! d+ p0 I, y* o6 F% s
sel = new Selector(Class.forName(name), method, false);! [ p* S! b( P. B
} catch (Exception e) {; E" }& O6 M9 K/ D
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ x: z) J& s' S# F6 y- a
System.err.println(name + "." + method + " returns " + e.getMessage());
' t: [2 t/ S6 f6 p- g System.err.println("The process will be terminated.");
! {9 U! t- G4 H System.exit(1);5 M, c, s2 ], Z( M4 k, n$ m
return null;" }4 z& u2 R0 H! Z' A9 D8 ~% o" D+ @, W' p
}
7 B5 j P! w4 W return sel;3 a! q% }( J" X- `; H
}$ Y6 d; H) V' p' Y1 O) q5 E* O" n
! H: M- a/ C8 N- f6 a2 }+ P public static Selector getSelector(Object obj, String method) {$ e: a2 i2 g* _5 {) ]3 I8 ]
Selector sel;3 c3 g& ~6 _: L9 G) R- d2 q
try {, x2 D" L$ n' h' J$ E6 B9 q7 T
sel = new Selector(obj.getClass(), method, false);; _1 n- F+ n0 L! e- v/ C) p0 R" e
} catch (Exception e) {
, b% P+ H6 k$ V, m- X/ o System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 U+ l) @+ @2 {- x3 w + (obj.getClass()).getName() + ".");- k- s% z1 Q' @, ]$ y2 P' o
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 S7 O; O2 }' q7 g' q: i) ^ System.err.println("The process will be terminated.");8 N3 M" d, O: s
System.exit(1);& F7 k' w3 {6 z( h2 T, K( {# \/ q
return null;
9 h T9 a, ~( l* ~+ g }) M1 F4 q+ _$ Q+ m n9 s/ E
return sel;% S& F& d( s, u) x, t- K7 L
}& [8 p- B9 G4 \ w- Q+ T8 t7 C" j
} |