import swarm.Selector;/ l5 Z$ ]/ T- {/ G) N2 |6 q! L
6 W/ D8 y5 A- d( u) a5 V
public class SwarmUtils {8 n2 j$ y$ f8 R& r3 G
public static Selector getSelector(String name, String method) {5 D0 h; I2 p; o- d% ]; N8 ^
Selector sel;, f* |. ?% d* W
try {
' c# L/ [$ o3 ? sel = new Selector(Class.forName(name), method, false);% }$ r' R i- y! y$ _
} catch (Exception e) {
8 B1 H8 S! z3 a$ p9 a9 n1 Q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; f+ G) F' Y9 c: r! D& A2 w r System.err.println(name + "." + method + " returns " + e.getMessage());
) f2 [$ G$ U5 a8 n/ J% |) o System.err.println("The process will be terminated.");. b( l j# f5 g$ C- P$ a0 H6 L
System.exit(1);5 N2 i/ \8 Q: O4 t
return null;
" f: s' Q, T g: V6 @) H }
7 E! h$ R" i8 [- H% Y+ { return sel;
& Z: f3 y7 z2 F8 ]1 I2 h }2 Y, a: c" U3 R
6 h* Y2 m$ i) P5 k# Y
public static Selector getSelector(Object obj, String method) {
2 N6 A- L* M! R Selector sel;) o P1 R3 p/ u/ o5 j( Z
try {4 h8 s. b: @ E$ p! C0 _
sel = new Selector(obj.getClass(), method, false);$ p2 _" F5 V0 u6 ]& s# t
} catch (Exception e) {3 i$ `5 A% g: n" I4 {# d5 F; L. R
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 B5 n1 S8 l5 q' z + (obj.getClass()).getName() + ".");* ?1 y2 ?6 T6 L
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' w# R$ o8 h! O% v* K8 [" p System.err.println("The process will be terminated.");
) `. y0 X8 m( R% o7 \8 o; _" B7 \ System.exit(1);
7 S) l2 n% L+ l return null;
% m7 K3 w- H% ~- d$ [ }. N* i( {$ t/ M
return sel;4 g, I U$ K: ^. @
}
$ @& S {: @/ M% m: V/ l0 c} |