import swarm.Selector;
* R1 |# Q2 S, f7 V3 i7 L, e6 H5 `( P
public class SwarmUtils {
8 S! U! i9 `8 I- u' k7 f: Z8 w public static Selector getSelector(String name, String method) {, S5 P( U' D! @3 g3 ? O
Selector sel;
2 x3 U2 h8 a1 c# a' t try {
0 S4 Q$ l" W. K% M# N% I! { sel = new Selector(Class.forName(name), method, false);, J+ C/ F( N5 X/ d
} catch (Exception e) {2 p) `) z! [; s& ]/ R/ m
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# G* A" u) T8 U) I System.err.println(name + "." + method + " returns " + e.getMessage());
) O9 E1 l5 v* ^% X System.err.println("The process will be terminated.");: M3 i8 b# m& `- [
System.exit(1);0 p) F2 K: v" f5 L2 {4 [
return null;4 M/ Y" H8 A- e: @# e( M" J; } B
}
1 j" @0 ?0 j* J4 e! Z7 G return sel;
3 \) V! R1 A4 k0 |# z0 X% }$ { }) T4 m0 x) E% v- f9 e7 k
8 I7 @ R7 j4 R; B: T
public static Selector getSelector(Object obj, String method) {6 ` ]' G8 A* A4 [6 \' p
Selector sel;
8 H1 G0 c) D- d# D" x! i try {2 w! F! n$ B' c
sel = new Selector(obj.getClass(), method, false);
; M* N( F8 g8 ` } catch (Exception e) {' K* N/ e! T, _" L! V1 ?1 U% B
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% K S$ S+ g; Z& K! a8 C
+ (obj.getClass()).getName() + ".");
5 S# [, ?1 q( h2 N1 V) [3 v5 R& M) S System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
3 r! J0 ~' z# | System.err.println("The process will be terminated.");
% }+ v9 C9 d" ]# g: j System.exit(1);
0 {8 d! U2 {6 v2 @4 p return null;
' R) E1 g& _; b* N6 ]. C }
0 D2 n# k$ t" }& ^5 h7 _ return sel;
5 Y7 b p: n% H: T9 {- b" g1 T }
5 X. y. g2 c( W% ^- s: @} |