import swarm.Selector;
. J# r8 |7 ]' U6 M9 [* X3 J" x& A9 n8 L+ _
public class SwarmUtils {
" ?( ~( c" n N' _, S i public static Selector getSelector(String name, String method) {7 B2 i- f, A* [6 v/ C( R( Z" j" d
Selector sel;
3 k% u% F* j7 s( r/ d$ l: Z try {
0 f; x0 G6 Q6 m+ a1 W sel = new Selector(Class.forName(name), method, false);7 z6 _4 ]& e1 Z* h7 m4 `4 C
} catch (Exception e) {7 u4 [& N) O3 G6 A
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 k/ G& k. Q" g2 B System.err.println(name + "." + method + " returns " + e.getMessage());: G4 y- j" ~: ?6 p; i4 U I
System.err.println("The process will be terminated.");
, b+ N7 Q3 X# V/ \. N6 ~+ {4 M System.exit(1);9 T* D0 k! _9 K! s/ T9 y0 ?
return null;
, j& O: ?7 p, C5 J+ g* |/ X }- x! M6 x2 B" G9 G' y; \' L4 q' k
return sel;6 o2 } Z* K8 m, S& Y
}
- ~, u* B9 c/ ]4 X; B- `
4 X/ x( k, C/ S/ o+ M public static Selector getSelector(Object obj, String method) {
* {. ^* R) b4 F3 m3 ^: I Selector sel;, d e+ {/ m$ N" ~ Y
try {( o9 ^' p Q; ~# c% a) W, C
sel = new Selector(obj.getClass(), method, false);
. {/ W) c% p% |( K) @* u } catch (Exception e) {
8 ^/ f* \) G4 M' }8 I: a System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& I2 p+ e: s9 V0 z
+ (obj.getClass()).getName() + ".");
5 A3 o9 c( j6 J System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 j' c) m; J* L- r/ k System.err.println("The process will be terminated.");
/ G! c; E! H! e d5 F$ E System.exit(1);( l( o0 N: O$ H' r, Y' |
return null;
7 h7 n8 g$ S3 m$ _$ }( u# G+ B B }% Q1 w% M" a P1 z: I8 ]# L$ H' Q
return sel;
3 R3 { Y6 N, V }4 I: Q. ]+ g& L
} |