import swarm.Selector;$ r5 L0 w6 W! ^ g( _. r' \
7 j0 J$ o. [- i8 F! i4 T% r$ _- Mpublic class SwarmUtils {
) H9 Y X8 N" @ public static Selector getSelector(String name, String method) {; }7 h1 e. x$ m; a$ H! l
Selector sel;
' h0 x) w% k1 P2 |7 d try {/ f- O# w# T! ^0 e" ^3 e* x
sel = new Selector(Class.forName(name), method, false);
7 f/ P& j8 v% y: U } catch (Exception e) {: k# o+ V* t& [; F4 p0 V+ l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- n' s' _2 B# m, l1 E* J: {
System.err.println(name + "." + method + " returns " + e.getMessage());/ y, t: S, v' C5 l
System.err.println("The process will be terminated.");
" f$ f# w7 q! U8 ~2 j! Z System.exit(1);8 _ y- F( j2 k: m# w$ {" S2 ~* N
return null;: j- ]$ ^9 \. N& f. K' y
}
, |9 q! |) Z$ u return sel;
5 J8 L6 |, ^3 z% K9 a/ L/ f" x }
2 y \1 x, W2 U$ B: d, ]
- {1 y+ ?, M4 b7 S1 V" ?0 Q public static Selector getSelector(Object obj, String method) {
' W! k0 O& _7 a" s- {! D/ Z Selector sel;% {9 ^5 ?+ G* Y/ b4 ~- \' A. C
try {
& M$ u5 E# ~" }4 W7 k* Q sel = new Selector(obj.getClass(), method, false);
9 m, P+ ~, y# q9 D, G8 f( Z } catch (Exception e) {# i% k& J% F6 i( t; @" K
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- |+ K/ u0 S) J/ N: T + (obj.getClass()).getName() + ".");' r8 q- n0 B5 P k1 U9 m, c
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( X* h9 x7 P3 t! E( L6 V System.err.println("The process will be terminated.");4 T l2 z4 {7 h) i2 \
System.exit(1);& K& P+ b: Q; ]. w% F' H0 P
return null;
, k$ }: m6 k" P& f }
1 T8 Y3 _0 b8 _/ B return sel;
- b) R9 L0 P$ o+ s6 E }
8 n7 B- k& [0 n9 g& {; |} |