import swarm.Selector;
9 v6 O. i: Q# k" d/ ^6 G7 l/ r7 g
- q( v P/ J+ p7 U* ^public class SwarmUtils {! x5 F8 g0 Y U' `! Y3 J
public static Selector getSelector(String name, String method) {
! h! \! E7 B. K; ~- t% `5 M0 P Selector sel;- p2 I- ~3 j( o) t2 T# |8 g! A
try {
. V# Q. L% c" I3 Y sel = new Selector(Class.forName(name), method, false);
3 p5 H) G2 P: y7 R( c } catch (Exception e) {
! D( a1 {* Q8 A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& N3 j; o2 x7 ?: ? System.err.println(name + "." + method + " returns " + e.getMessage());
w2 `8 S* \9 t' ? System.err.println("The process will be terminated.");, E1 S7 [( g( W" T p! ^! u
System.exit(1);$ ]; N4 ?$ q( K* @8 t
return null;, W; t* W& M1 }8 B' l% m4 A. I
}
. y6 v! Q4 k- a0 j) N# c return sel;: }( F3 M' W ^+ D
}( i: g$ Y6 b- x1 [$ n
" H5 R& d. Q8 P3 ]6 v3 H public static Selector getSelector(Object obj, String method) {
' N$ R! i, {/ F. [# i Selector sel;
8 t7 ^" p I) Z6 H- O0 D try {
6 G; E1 N$ b c# e sel = new Selector(obj.getClass(), method, false);2 C; N- `& R) C4 b3 k7 i
} catch (Exception e) {$ G3 C% |+ D/ \2 b q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! G! E2 m! t' l
+ (obj.getClass()).getName() + ".");. T; g7 c$ c( O7 ?9 L
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ I) B; ^% V9 {+ k2 z8 C5 u
System.err.println("The process will be terminated.");
% D3 |: G# F: E System.exit(1);! g: q3 Y& ]7 \8 E+ [* s% R! V
return null;
& T' |' a, f) { }
8 y( K( Y3 ^# m5 S return sel;
2 M6 V) E) [& w }
* ~0 D; h: b; {1 h# L" R} |