import swarm.Selector;$ G- J2 p3 S! r1 v( \9 g/ d
! k4 P: g M; s. `" b
public class SwarmUtils {- \# k: l o& b
public static Selector getSelector(String name, String method) {/ |; N8 P4 t& _8 f
Selector sel;
* d' y6 Q4 ]8 O" l0 Q1 q, M try {" }8 s9 `9 Y8 m( ?5 B
sel = new Selector(Class.forName(name), method, false);
' o0 ]" `, S# C3 T- D1 M } catch (Exception e) {
( z- |4 ?5 A ^( F. K$ s/ W System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");! X, l+ _7 P3 o4 S8 a& I, u
System.err.println(name + "." + method + " returns " + e.getMessage());
0 ^3 S% e7 R. z {1 ~* i5 { System.err.println("The process will be terminated.");
; L9 J* G& J$ F# [% _ System.exit(1);" Y% X/ W! Z1 x! [- X: B* h# ]
return null;# K! C/ ]# T8 f1 D+ d7 x
}
, t% `1 U- |" B- ]* a/ N- } return sel;
6 K# m& l& p. I& O0 R }8 U [( t7 E5 b( g2 }/ {9 U8 g
( j8 N5 p# ?) F
public static Selector getSelector(Object obj, String method) {
8 ~7 {4 J/ S- l- M# [, u Selector sel;* }( T- E/ j1 o5 Z' k N+ W0 S
try {
& a9 G5 k6 o/ B, f+ V0 p sel = new Selector(obj.getClass(), method, false);
) N$ p( Z: t( w) M3 P } catch (Exception e) {
* Q/ `9 V+ p+ @4 \ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 M1 [# m- [1 U% P- v. {+ x
+ (obj.getClass()).getName() + ".");% }' @ A- {0 `: b0 D% J5 n
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 N' `& o6 n2 i* a' w% b) C2 { System.err.println("The process will be terminated.");
. w" C8 _. X" S6 Q System.exit(1);; M! y7 \" \4 D0 R
return null;- L, J4 U: o" w
}
' F: j& _5 g' _3 a; S return sel;* f+ V V; R5 H8 e4 s+ e4 O) V# N
}$ j' r* j+ w+ ]" I" p2 A1 [2 Q1 |; V, m7 I
} |