import swarm.Selector;8 F. j8 F, @6 i$ Q4 W( ~
( b& h3 F5 |7 n
public class SwarmUtils {
( \% d$ a7 n: e% t& C" e, N public static Selector getSelector(String name, String method) {
2 p& U: I) w( x; Y( k Selector sel;/ z( K- _+ d1 w/ }: n6 M
try {$ M- o1 G5 y7 q* E
sel = new Selector(Class.forName(name), method, false);. d! m: b" e) |3 w
} catch (Exception e) {
3 [( F: \6 d+ A/ Y$ N# L System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( J; G! C6 _& c3 \
System.err.println(name + "." + method + " returns " + e.getMessage());6 D: c: M# e& k- l+ x c
System.err.println("The process will be terminated.");0 J0 s6 {5 v% H( F
System.exit(1);
1 J' U5 L! @# T return null;8 D; S+ G5 P+ R% Q) a$ ]- I( R
}
! x# {0 i1 n) Y) u Y/ z. S7 { return sel;
9 e7 H* ^5 @7 K/ O5 Y }: S. W+ v% P9 N$ `0 i, j* v
( v) O" _' I1 T: o2 \5 E- e) D' ^ public static Selector getSelector(Object obj, String method) {
4 o2 f4 A' T& X* p% ?( s Selector sel;
0 E* K: f) R n try {8 n i4 T. _( [! c P* g
sel = new Selector(obj.getClass(), method, false);% e+ v% K* ?- Y8 w/ _+ ~
} catch (Exception e) {/ D4 n9 r! z, I v& [; J: U
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "3 \8 c( b' t5 k# _2 x; x7 H
+ (obj.getClass()).getName() + ".");, n0 @# Z9 K. J- H
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ [; v R) \# ?$ G" K$ I System.err.println("The process will be terminated.");. P/ p8 Y9 s3 j& E2 P0 t' W% F
System.exit(1);
+ D# ?- s0 D& u8 A1 I( L/ U% g return null;2 J7 m5 p) ?& S6 M% G' D: o
}3 K! X( h+ J) `' |. s" N! }5 E
return sel;% \" `; s: _3 L5 y3 B. v' C
}( ^2 N8 K( ?2 S
} |