import swarm.Selector;
% u" l/ S/ n; f0 W- m8 z8 @
c& S* W6 r4 }0 Apublic class SwarmUtils {
) x2 T4 f. L* ?' d, s2 l a public static Selector getSelector(String name, String method) {; ~& U# c( o. e0 I; [" V
Selector sel;3 V* o: X/ |0 j" o$ c8 N9 t
try {
! I& |) C4 n7 ]5 Q; X9 s7 c sel = new Selector(Class.forName(name), method, false);
! o" V( ~5 D* B, `3 R) ~) o7 t6 ~3 x } catch (Exception e) {
; a+ P. q! j& I# T( [. C1 _ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");+ e6 g1 a2 F( Y' u5 w7 C# E# p
System.err.println(name + "." + method + " returns " + e.getMessage());
6 q* L" J7 `/ ^" U$ L& U2 w System.err.println("The process will be terminated.");* ]8 K+ V. N# Q' S; Z
System.exit(1);
/ E' G% q; ~, q& W9 ~3 {) K return null;8 {- I' b' `) i, ]6 T2 S
}2 t" [! t, L8 l% @) ?7 m
return sel;
|! g8 [ p9 C$ f }8 u+ {, Z. a: i) g' W
7 R4 v& a. G' U& b- k' m6 f8 \+ {3 ~
public static Selector getSelector(Object obj, String method) {
6 u% Z- g, b k# T. j Selector sel;
3 p1 G, X' \% M try {
' k+ P4 h" y/ Z8 d) b, y9 H0 O sel = new Selector(obj.getClass(), method, false);
) O, {5 M( R+ }' K, e } catch (Exception e) {
$ D, [/ n2 Z, B System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% r7 Q# f+ w9 P
+ (obj.getClass()).getName() + ".");
@+ m. C; i5 m+ }, }6 R! m9 f System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
& t- z" `) B" M5 Q System.err.println("The process will be terminated.");
M8 ^: N) e) H) X* P% u$ c% r System.exit(1);
: r8 Z! r3 N5 r' c. U- Q# ? return null;* f! o- E" r: r' x: N( c
}
4 A, N: D2 ^6 D4 J return sel;
- h# l. q2 k- I- B }
' X2 l% Y5 D) l# N, B} |