import swarm.Selector;
; T0 j: H: i- @$ _8 H a1 T
" Z& d* `. H- a# m) `" {8 K5 Vpublic class SwarmUtils {& I/ h! _7 ]( G" X* x. I
public static Selector getSelector(String name, String method) {
8 J7 V- h, N* u. I* }9 ] Selector sel;
/ B5 B" |, u9 [6 t7 d8 @5 a try {& _3 g: D! C. V% U- t
sel = new Selector(Class.forName(name), method, false);
- b% R9 \, o, X# Y" _+ N } catch (Exception e) {9 T* K5 q, s+ }3 i. i
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");$ Y0 U) ]' Y3 z7 `9 _
System.err.println(name + "." + method + " returns " + e.getMessage());3 y2 C; U* @, o/ P
System.err.println("The process will be terminated.");" W B* o) C4 l
System.exit(1);+ C$ X5 f! s; {9 z
return null;
* L/ T% i+ F8 J6 V) d }
1 U, Q; u; N7 K4 y8 O6 B5 ` return sel;. h# S# f1 l" f
}# u; E2 Q6 f0 j; }5 q
4 |: {9 N* R A+ [
public static Selector getSelector(Object obj, String method) { Y! |. o2 Z4 z, R7 I$ @- F$ R
Selector sel;
! D a3 b" O- t) e. J; [ try {* `3 X2 F- ~6 H$ b. J
sel = new Selector(obj.getClass(), method, false);( o1 P" V+ p$ v- H5 h) X
} catch (Exception e) {
! k; y/ |+ l! I$ L# y: E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", p: t# r( O* H2 Y8 ~
+ (obj.getClass()).getName() + ".");% c5 ~" a; t, q, Q
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; O! ?" J9 U/ {$ z# J6 X8 h
System.err.println("The process will be terminated.");
% d& `+ u8 J% x( ` q System.exit(1);2 q. K0 }5 l4 E9 j2 N
return null;
2 W% | E0 M2 S6 |7 ] }5 y+ |( j* [1 i9 A4 r9 \$ W% C `
return sel;
3 F1 @5 c/ Z% M9 ^7 d( Z' _ }
6 A* j3 p# C: q7 M6 _} |