import swarm.Selector;$ F# {' E* i( q; ]4 X, h
" k5 i ^4 Y$ I2 j1 F# `public class SwarmUtils {: H6 x9 T$ {! W8 E4 d+ ]7 W
public static Selector getSelector(String name, String method) {5 R# s. j$ d3 q8 `5 u7 @% t. K
Selector sel;
r; z# j* e" O% `( ` try {; b- _5 U) ]: Y+ w
sel = new Selector(Class.forName(name), method, false);
; T9 Z0 m( [. V9 F3 c } catch (Exception e) {* j6 ~0 j5 h& ?' w
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" ], }3 z0 h1 E System.err.println(name + "." + method + " returns " + e.getMessage());9 P% @0 q8 q) k* f2 J# C
System.err.println("The process will be terminated.");
: j9 ^- ?4 o1 P System.exit(1);4 C4 o1 R$ d! J
return null;
u: d: C4 h3 [$ q0 h6 m/ b3 v7 z }# L5 v, o( F# B. a% x- A
return sel; x- r9 L6 H6 W
}0 R% P; o$ M: H& ?( g1 I
6 j& l9 T/ v/ R2 g9 w public static Selector getSelector(Object obj, String method) {
7 `8 `$ H5 y0 ~$ L( n# e, O8 B Selector sel;
1 C/ g* h5 `, q try {% U$ F$ d" d* W. W
sel = new Selector(obj.getClass(), method, false);
9 r* ^3 |$ a G- A } catch (Exception e) {* v+ l6 d- r0 c3 c
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. r7 z* s% A' }; s9 u + (obj.getClass()).getName() + ".");
0 Y6 Q7 Z! \1 T) r% Z: c' C System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' ^# P8 y' V. p' o2 i' ?2 L- g! D System.err.println("The process will be terminated.");+ `; d' g' R) S: e
System.exit(1);
$ N2 n3 ]- ~" U% K, w return null;& _8 q/ M& [- V- [- _1 \ `
}
5 e$ D$ Q9 m( u return sel;6 N; J7 s* `) v: J) y! U
}
: u7 |, |7 H7 B8 K8 O' h: ~2 f} |