import swarm.Selector;
4 T! W1 r1 v: `8 f, p) T6 e/ s# E4 \' b' {- v2 i, [
public class SwarmUtils {
2 ] N0 r4 J+ M0 |2 W public static Selector getSelector(String name, String method) { X/ l+ @. g& }- x% O z0 a. e
Selector sel;
/ U( q$ A# E/ k0 ^- g try {
- E% D- |) w1 A9 ~ sel = new Selector(Class.forName(name), method, false);
0 m q! s+ O+ l& G) N } catch (Exception e) {) K; J) l* G9 [
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& U9 H; X" ?9 S7 M! B System.err.println(name + "." + method + " returns " + e.getMessage());
) h/ B: z$ S* v. G$ X System.err.println("The process will be terminated.");/ b0 C" o/ t, R6 ^) V/ z9 [
System.exit(1);# t9 H2 `9 ^6 h; A2 |: _
return null;
* {2 J: f5 U8 w- g( \ }5 { E1 P6 ^1 Z$ `% V% C: x
return sel;2 [# R/ Y' a/ f; x
} x* }( R/ e7 ] S% u
5 }( j# s8 C6 l# b( h, B, G/ i
public static Selector getSelector(Object obj, String method) {
8 Z/ n7 w1 f6 g" e9 {0 Y# K; b2 M Selector sel;" ^' k8 A% M' Z" c3 L3 N
try {5 b% u( m5 U, \5 o
sel = new Selector(obj.getClass(), method, false);+ K' Z ~, ~$ o" n
} catch (Exception e) {- U, G$ ~% e y& p3 u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "( Z0 n9 |7 N! G, U+ L0 U
+ (obj.getClass()).getName() + ".");
; _- ?* V; S% U0 r1 v6 ^/ }% K9 M System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, N+ ^7 G p" D, h
System.err.println("The process will be terminated.");$ H" a& T2 z: j' ^: T2 j$ l0 L" d& h! `
System.exit(1);
7 s9 p: p. }% k return null;
0 x9 }+ w' l7 P+ E' Y) S2 b% n8 \ }
# ]8 T# D& D k& ]8 r+ z+ M' D% j return sel;- L7 s1 D& d* ^* |
}
: I6 d: A& T; V: F( R% ?( H} |