import swarm.Selector;
4 h5 k+ a! J0 Z7 N% z7 v9 @# g6 @& j8 }! P
public class SwarmUtils {: N0 b" R+ v# n* z- `5 A" D( G
public static Selector getSelector(String name, String method) {, ? }, I3 f9 a" N3 U6 Y l
Selector sel;' K7 v; {: e5 ?, w
try {# h% e' _* ^4 L! L. |1 a
sel = new Selector(Class.forName(name), method, false);+ y" a. B% O9 N- K& F4 H
} catch (Exception e) {
) m- ^! M" E! \& J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 D$ G. Y7 B! a/ M4 S0 D
System.err.println(name + "." + method + " returns " + e.getMessage());* e6 l% N! p: K4 D6 y% `
System.err.println("The process will be terminated.");* k( p L6 u- Z
System.exit(1);3 O6 k/ i1 s1 l3 k# B( d
return null;
q9 B9 m' N# B% m' F* H9 e }
0 ~, |5 ^# _% X n+ g return sel;% R, }, U7 r C) p6 x
}
" k8 ?4 D# t' r" M, }4 T6 @9 I l. X1 @- k; \
public static Selector getSelector(Object obj, String method) {
* f7 u* O f2 G0 b" {. y Selector sel;
( q3 ~7 }5 l7 z# Q& X9 T( Y6 i$ y try {
1 v5 s% F! g f sel = new Selector(obj.getClass(), method, false);
" S @( [. E- ?8 v/ ]2 V. t5 t } catch (Exception e) {
1 O* f4 [2 _6 D5 o l System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 B. H: q% g! ^, K- _" j( E6 | + (obj.getClass()).getName() + ".");
3 a* U) T5 K1 @* Q+ h% n System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 D5 S; _0 N* p4 ~1 |
System.err.println("The process will be terminated.");7 v( f0 K4 C& V4 x. N; p0 X& }
System.exit(1);9 z. `1 [! X$ T, z2 ?, v( Y1 S& i
return null;
: i7 E! v$ S7 a8 u+ [# k( I. Q7 i }# n H! x/ F: T$ v$ B; c4 r" c
return sel;/ Z' u( H6 m4 N
}
$ z& p3 a: H: W9 G+ U' }7 h6 \' V} |