import swarm.Selector;
5 ^8 r' ]" z1 [4 e
3 |# f5 p' @, _public class SwarmUtils {
2 e+ m- v* e) s: S7 g& e) q$ B0 W' y public static Selector getSelector(String name, String method) {
2 P* Z/ f. z3 I0 e" S$ W1 G7 d8 C Selector sel;
$ l# x( a" Y* Q: ]- r try {
) l: w3 j$ {( |1 I sel = new Selector(Class.forName(name), method, false);
( V8 Q" X, @; B! {% ?, \ } catch (Exception e) {$ @3 V7 n2 @5 u: x t* w1 a/ r
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 a t# H& |- i4 M* u System.err.println(name + "." + method + " returns " + e.getMessage());! } V9 |( Z( a: `8 }
System.err.println("The process will be terminated.");
# c+ K, ?7 `" i0 e; n J% R; A5 s System.exit(1); v: P+ F6 ]) J1 @' P( K
return null;+ u& B5 V1 T, C
}
4 Z6 b! {8 u. m9 ~# ~ return sel;7 @2 z8 b- E( j2 z
}
) l) [9 V) Z2 J+ m# j Z7 o* W6 f Y& D
public static Selector getSelector(Object obj, String method) {* O2 ^. s3 B& ?
Selector sel; k" n6 w& H. W O( C# b: Y& J' @; e
try {
: V- ]0 w' G/ a3 F! M" Y sel = new Selector(obj.getClass(), method, false);
* C+ v6 A! @( R& ~) U } catch (Exception e) {; w1 {& I* n8 [
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 D& i' j( H" I- Q+ S + (obj.getClass()).getName() + ".");; J3 |5 b: V4 a. F
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( n; w/ M, j( c
System.err.println("The process will be terminated.");% p( k# D @# E, E K; o
System.exit(1);
8 M/ c" s- \( ^; A return null;
' c- {, m7 K. x0 d4 T }5 m. d' y6 |0 a& g" b/ ^( R
return sel;
2 R# a0 o/ \4 y; c1 M0 N6 o3 g }! h: P. b! v) A P& ^
} |