import swarm.Selector;! u' Z, T' k% p4 \, ?
# x& V3 f F1 S+ r9 B! a" S7 {6 gpublic class SwarmUtils { z( y9 p2 K2 h$ g# ~" [# R
public static Selector getSelector(String name, String method) {
2 o4 z. y4 }: Y Selector sel;
5 |8 o$ v' H* ^- H try {
1 {( V+ A- a5 v4 ~ sel = new Selector(Class.forName(name), method, false);9 o& m4 D3 P6 O6 H) @/ u) X
} catch (Exception e) {, k4 h6 n9 {0 m8 y. d |* D
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 Y1 j7 _. B$ V O
System.err.println(name + "." + method + " returns " + e.getMessage());
, E: E7 b a- p; t! u& o System.err.println("The process will be terminated.");( e/ b: q1 \; h8 p/ p
System.exit(1);1 O1 y2 p' l M/ z
return null;
" c# `! X6 S1 L; }1 J# B7 K$ Z8 ` }
7 Z; z+ ~( K1 k4 B3 \ return sel;
* D4 x) |9 w' ^) A }; \' J6 f$ ], z; ^8 H( X
; F; @4 V: B: ~( T& b3 H! P! E
public static Selector getSelector(Object obj, String method) {& B! Y! Q. j) I# H& }
Selector sel;
; {, Y, d0 K5 Y9 H1 K F: g try {
. a' c$ J' `* m5 n sel = new Selector(obj.getClass(), method, false);, [* C7 B0 z( T7 Z" v g; G6 t' l. M
} catch (Exception e) {
% m0 W- ]2 b' e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& N" c; ?8 c# g# n: b. g; E + (obj.getClass()).getName() + ".");
; |# O5 M5 O8 H# u: U/ P System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: C. Y* N7 x& E/ [2 J, @ System.err.println("The process will be terminated.");
: Q5 [% A* P; v6 |" T& L System.exit(1);2 N0 n4 H6 |: x2 ^9 K7 N
return null;
3 z) e( r; ]: J9 \ }
5 `5 E' k# P6 G3 K, ^ return sel;( |' z, [1 K) m: |
}6 F7 Y" e5 f. x. M$ J
} |