import swarm.Selector;6 }& S" Z( b0 Q$ }1 F- s6 v& l
" P0 ` J4 r3 |9 N" l2 C( k
public class SwarmUtils {
& c- @: _4 u, `/ d/ g/ U5 F! f public static Selector getSelector(String name, String method) {; `3 Y! H9 ^2 m! z
Selector sel; D; r" C6 s+ p! H2 N
try {! j, i3 b1 M) U _
sel = new Selector(Class.forName(name), method, false);
4 g( C" Y* g5 A& m9 E } catch (Exception e) {
4 t/ ~. f/ U4 X" J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ n1 A, t' u' r5 g6 N+ V/ z# a System.err.println(name + "." + method + " returns " + e.getMessage());
- D7 Z6 \2 J* R/ j1 w; A9 F! t) M System.err.println("The process will be terminated.");
( v7 x5 r- f, u/ Q; b System.exit(1);3 \& a4 J2 r& v( `
return null;
' a0 ?' t- [4 o. i8 Y* p) a* d }6 J/ ^. |" ~4 z4 P# `9 M
return sel;
7 b* Y! q* w! d) g4 h+ v }- k" s$ u# x; g `% K0 E0 j! L
: G d( e( O! |8 ~) \; Z/ O- k
public static Selector getSelector(Object obj, String method) {" m' m C2 B6 e7 ^' V8 r
Selector sel;
L$ a$ A0 j8 C# y0 z$ Y7 q( V* M+ n try {
0 `% O. }' A! m% [9 \6 t sel = new Selector(obj.getClass(), method, false);8 C0 |" V) V0 c% Y% N6 n/ g
} catch (Exception e) {# d% \7 U3 Y: l$ Y
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 ^; U$ ?: {* b2 A. J + (obj.getClass()).getName() + ".");
5 l" \0 J7 Q# x2 _ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 `/ A! I/ C( Q& G' S: q& Y; @5 F
System.err.println("The process will be terminated.");
& N& A7 R5 w5 l7 g, y System.exit(1);) `, }$ r: R( J/ m9 u
return null;; ^* j6 X3 Q, a/ Z9 Q3 F1 U, }5 c
}
6 R" Y5 q- g9 S! s! k& B) D2 ` return sel;
1 L' m0 `' N5 j' E }' @( @0 d" K; f# d3 l
} |