import swarm.Selector;0 [. a) M; g: z- [: u8 {) d4 b
% I) q9 p- |- `5 X7 o6 c M5 U
public class SwarmUtils {
; D- ^; l) @4 [1 W public static Selector getSelector(String name, String method) {9 m0 _8 k% a' V/ N! e, b
Selector sel;
3 B5 |; q& h& B3 C! x: t* y try {; z& d, a f1 |' d3 q, P+ U
sel = new Selector(Class.forName(name), method, false);, D' r8 w* w! U, }* l
} catch (Exception e) {/ N$ n9 j0 Q4 m z4 O$ }; F
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ Y& _4 U0 |" q' }5 V
System.err.println(name + "." + method + " returns " + e.getMessage());
/ g6 ]' ]. x z9 U4 D System.err.println("The process will be terminated.");: n- L0 M/ r0 n2 _7 g5 v: b
System.exit(1);% L& |. V/ c, \5 X/ x
return null;
+ W9 L0 k( a9 F2 X1 Z4 y# t }2 b4 W+ `- a/ \9 s8 b
return sel;
. U8 T( @+ K) }. n. p. S }
: Y9 b& z" s" ?' V- \+ ]8 T5 T/ y; u* f4 D& b j- o
public static Selector getSelector(Object obj, String method) {% v, U) O! x) Z" d1 y
Selector sel;
7 K7 N9 K: ^% V9 q+ m0 I: T' M: s try {
2 C, Y- B* q' Q$ B8 K* t/ U sel = new Selector(obj.getClass(), method, false);
- ~% `6 \ R0 c* V! ^8 T } catch (Exception e) {
8 H' z- H A8 X9 H3 q9 P System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# X3 a, ~. `- E0 ^5 K + (obj.getClass()).getName() + ".");
# u# n& {5 s% U+ K: d System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 T, f! n8 e$ o3 ^/ ? System.err.println("The process will be terminated.");1 R. W/ @: W8 J! \9 w6 c
System.exit(1);
9 M5 `, S6 O, q" O' J1 E& Q return null;
: t, V$ h. D) l$ y }$ B1 {4 N0 S a, Q6 L, A
return sel;- { v; D2 C* a0 L
}
2 w. C O( e, F, o8 ^( X# l R} |