import swarm.Selector;9 v( c% i8 G# [8 D
: k7 {9 n, [: E" @2 T/ z" P
public class SwarmUtils {$ g/ ]) J, [7 C* s1 Y5 p9 @
public static Selector getSelector(String name, String method) {
$ M1 s4 L4 j" x! B8 v. d6 c( z Selector sel;
& V, F, Y' d, ]- e8 a+ N+ F* ` try {
Z& y; S. K3 u! z5 { ?: k sel = new Selector(Class.forName(name), method, false);
2 k" [8 t. ?9 }& o: z% L% \3 S0 ? } catch (Exception e) {
/ K% Y. R0 B( }8 w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 C: p& ~% B' ]0 u# |4 C; e
System.err.println(name + "." + method + " returns " + e.getMessage());
0 R# @/ I; E4 @* t3 H System.err.println("The process will be terminated.");
4 L9 H- P- X" s7 b+ N, c6 f+ \ System.exit(1);
/ }% f# a8 c8 J" z return null;4 z& U0 b) z; n5 x; V3 u
}8 w/ C) K; G: q6 m2 b) U7 q- x
return sel;4 M4 R0 J% Q$ H3 V' T' N; ]
}9 D. o3 N( ]1 ?. G, I. L) m
8 D1 d& j. C6 c: z$ j; s7 y3 E; w% m
public static Selector getSelector(Object obj, String method) {# p R* H9 N" r5 J* N% D' i$ d
Selector sel; ]* n8 m) S: ~9 n9 c1 U7 r- U
try {" B/ f! v( h7 C% |+ f+ b* c
sel = new Selector(obj.getClass(), method, false);& e$ ], ~6 g8 P" r
} catch (Exception e) {
- i: z7 F& R1 I8 k+ m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 M% D0 m$ d( b/ S + (obj.getClass()).getName() + ".");# c j' a2 l! x4 g
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ I- _& m+ B; y! q System.err.println("The process will be terminated.");
& w4 m- R2 B: n' y$ P System.exit(1);4 ^( ~5 e! j3 [
return null;
9 E# F8 a5 p" }( g }
$ ?6 J A+ c2 @" j( N/ e return sel;8 }4 S9 \! X* c5 q' O
}7 z9 s9 l4 }- G' J/ ?
} |