import swarm.Selector;$ Y9 J8 e+ i& p: F0 G0 I& ~
6 `4 b! `/ \- E0 C+ h& D
public class SwarmUtils {
( j+ g8 `+ c* @' E1 Y public static Selector getSelector(String name, String method) {" f* }" x* \2 G& O: A8 ~
Selector sel;% _' N4 o2 G0 E7 @4 o
try {$ T% }" H6 p# |' n& F0 Q% i, i
sel = new Selector(Class.forName(name), method, false);
6 C" b& H* x, U5 i. G' m } catch (Exception e) {
6 x7 q5 [* B( C- Y! J* D1 t9 F5 d8 J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
U* L- r3 O) l" J& S# _! b System.err.println(name + "." + method + " returns " + e.getMessage());
# q/ k$ i1 P# K: p; p System.err.println("The process will be terminated.");
- O8 {0 a9 D& I2 y# Q9 S: O System.exit(1);4 e; ]; k0 s m' E5 M1 d/ o6 T" @
return null;
" Y) E/ q- T5 t; R4 i }
( T t6 s7 M3 X/ Y+ G9 i' \ return sel;
+ W- |' o$ j- [+ V2 m) _ }
! W& Q& x6 L/ m( ^7 \5 @* z3 I# H! A, [) E5 `
public static Selector getSelector(Object obj, String method) {2 D' e. z" a, S# ]
Selector sel;
; @; u! L( o- S: i& w: ~% s5 o0 }0 j try {& d8 O2 T" n5 ~
sel = new Selector(obj.getClass(), method, false);
' X& p- Y% b( a S8 x4 Z } catch (Exception e) {
& M3 ~' e, M* B; b System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 N5 h, y" e6 y* C* A + (obj.getClass()).getName() + ".");
; d" k& O: ]* i7 q5 N, ?, y System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 l+ u" S! ^8 r* K" `
System.err.println("The process will be terminated.");9 G V3 K: d0 u0 |
System.exit(1);
& j8 u0 g8 e- ?; C return null;" A! Q5 j. l' f- G
}
' [$ R9 @6 ]) D* e0 \; a6 @ return sel;( Z2 E& Z5 M0 d- V$ S
}+ c# z& B' J) l8 s
} |