import swarm.Selector;
5 m% F6 D! u. J7 b7 F$ O/ c4 J9 y8 D: @4 m# O1 D
public class SwarmUtils {
; M# s i0 o# e: Q( r5 w( @# \: {+ w public static Selector getSelector(String name, String method) {
2 \% p1 V9 C N Selector sel;7 z& }0 @5 m9 m& F" |) z. B M
try {
7 c, b4 v0 [ b* z# e& j8 L sel = new Selector(Class.forName(name), method, false);
" Q d* `$ E/ d } catch (Exception e) {! L o+ M8 Z& \# C0 B
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 D, s# \' z, e System.err.println(name + "." + method + " returns " + e.getMessage());( }9 X% k" B4 k7 s6 V
System.err.println("The process will be terminated.");- i" d: m A8 m
System.exit(1);+ @! n i) R- e5 H6 F* `" w
return null; C9 q' h" W, T, f8 B" m! x
}
6 `; X' w8 s9 U2 c return sel;
5 Y C1 ^2 C4 d% L; Q }
; e' j7 S% B5 r
6 c {# o/ ^& T public static Selector getSelector(Object obj, String method) {
# h, n' [9 m% V1 p8 L- q0 ]# \ Selector sel;! L# l+ c Q% z" r# n D
try {$ O& x5 C8 v4 ]" q" w8 [* a
sel = new Selector(obj.getClass(), method, false);
, t I5 _5 a$ {& k } catch (Exception e) {
' _* h0 ^: h2 ?: ^( | System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ T1 ]/ |9 a$ A0 o5 x5 i8 R + (obj.getClass()).getName() + ".");, n# F6 G5 Q% x+ i- M. C$ Z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 M! J: u7 X. c# m z System.err.println("The process will be terminated.");
0 w$ @( L, J! ^9 U2 r$ z System.exit(1);, @7 e3 l" l$ |0 p
return null;' J2 L/ P4 g* Y% X- c4 D, C0 k4 R
}
5 f9 ~! D! s/ O( F% T1 l6 X return sel;! M. g Y" h5 o8 V; `: a/ I
}5 x Y1 R3 P, V1 `3 [
} |