import swarm.Selector;# p# g/ c+ v3 l& n4 d' K, `
0 M2 {. a5 b. }9 ?3 x4 k2 e
public class SwarmUtils {
% u, }) r# ^4 f9 E q& f4 } public static Selector getSelector(String name, String method) {8 N$ m$ L$ {0 C- t$ m/ d
Selector sel;
3 g5 a- s+ v: S7 F4 J6 } try {
' V, V8 ^: `% }- y& B+ p; f! O sel = new Selector(Class.forName(name), method, false);# x' b* w3 a8 r t$ O+ i' T6 W
} catch (Exception e) {
1 b2 T( }8 ?; L8 Z5 a System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");% ?$ ]5 Q( v& ]) E# H( ?
System.err.println(name + "." + method + " returns " + e.getMessage());
( q3 @: F [ Q) v4 z System.err.println("The process will be terminated.");2 \( b7 y4 L1 w. ?
System.exit(1);
- U+ W2 U4 @4 t; p6 s return null;
- c, g* W; ?' b$ e* [) R9 R }
& V' p! {1 a8 Z( h& U2 \ return sel;3 q* Q+ J- S9 t/ M
}
; W: k; {/ O: F: o6 J! |/ v' I" D$ c& T K' N8 @
public static Selector getSelector(Object obj, String method) {
9 C; I8 G3 C" o) F. h" C( r$ m Selector sel;
; Z; k6 G9 \8 Y% X try {* Q8 e6 O0 u+ W: X! ]: ?
sel = new Selector(obj.getClass(), method, false);
7 J1 s9 E% J# b/ N, J: S% r% k! I } catch (Exception e) {
9 B5 B4 Y' x0 N$ ^: E3 q System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
2 h; K( r1 Y" G# j/ g; l + (obj.getClass()).getName() + ".");
5 H. }2 \! y- ]' S9 [ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 U1 c' G$ c/ g; x4 W System.err.println("The process will be terminated.");9 b: |' W5 ~8 x& u. u* m+ U
System.exit(1);
' p$ P. t6 d3 w$ P return null;3 B4 _5 U0 y& n. T
}2 C T+ L a: H1 s
return sel;! I4 X S' D' G; `; D
}- B6 `+ q! S& ]- Z1 B9 i8 _# _
} |