import swarm.Selector;
y0 P# b6 G3 _- L, k- o* \- Y' l4 f5 X2 _% }1 f$ c. v
public class SwarmUtils {; L9 t( S' d& K' a7 n( f# L% J7 Y# L8 r
public static Selector getSelector(String name, String method) {
, [( K8 J8 s ^/ O) w/ Q- x( v5 p5 w$ \ Selector sel;
' S8 x" Q$ E$ g" A1 Z try {
7 Q7 x; T: S- g4 x4 ?9 {' u5 a sel = new Selector(Class.forName(name), method, false);
! V; J5 p4 D9 h; \- J! r( m } catch (Exception e) {2 b" f" t, {1 r
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 a. h, M) Y8 Y- G
System.err.println(name + "." + method + " returns " + e.getMessage());! s7 Y3 C0 T, |5 z! Y
System.err.println("The process will be terminated.");
* \& X* C: s; T8 J System.exit(1);9 K0 k& u& l+ Q; Q* ?9 F
return null;
) X: F- s9 Q6 @2 C }
/ G1 T, ?; A: F' b return sel;( Y- ^0 [/ r8 U4 c
}
* s2 N% F( R. T" F' I6 Q
5 W: C+ }! j; y$ {1 D/ ~ public static Selector getSelector(Object obj, String method) {# R5 s% }# O- \3 l8 e- v$ _: V+ C$ \
Selector sel;
h0 \! u; u4 b+ j1 w C try {
( A+ ^: {% c2 L( O sel = new Selector(obj.getClass(), method, false);, w7 c! q: J* }! ]; G4 o" m
} catch (Exception e) {
, E( M& S5 [# q+ {4 d System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. W. E# Y. h x$ G$ I + (obj.getClass()).getName() + ".");
; |! f! ? I) m6 Y4 f+ p System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 }5 m3 J2 M" I/ u; Z
System.err.println("The process will be terminated.");# R `$ |% V1 J! ?
System.exit(1);# p1 g0 X* `8 A8 K: W' \, i
return null;" p& P! R/ _, T T: z. z
}
. k* H) s0 p/ d* @' ~$ w return sel;
0 a8 t( Z9 r' [ }. n' y0 b) e$ S
} |