import swarm.Selector;) M; c6 I0 {! ^ ?: q7 b' d
& k: }1 q3 G0 d4 u
public class SwarmUtils {0 d; x2 V. Z' U) o1 N/ z+ Y% `* q; {
public static Selector getSelector(String name, String method) {
' [" i. _7 z3 m$ Z8 J Selector sel;* v ~* s9 i I/ ~
try {8 a8 p. o! x j3 m
sel = new Selector(Class.forName(name), method, false);4 a. O, C3 b5 Z1 @$ t6 J
} catch (Exception e) {5 |4 l: p1 Z5 v6 W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
1 W7 L4 Y! s$ b9 V7 n. F4 Z C& v) k System.err.println(name + "." + method + " returns " + e.getMessage());
% S6 G( m- e1 e) ~7 o- s) r System.err.println("The process will be terminated.");0 p; {, b, P- K* i
System.exit(1);* B \/ Q \6 h0 n1 J. @# c
return null;) s$ ^, \: d. T
}
+ D- C. O; z5 a# Q, ?7 W. Y3 v: t return sel;
) U' F9 S4 a" f, D# r; Y }
5 B, h* K! g2 x( N( L5 M2 J& ?: K% q/ v3 g% V
public static Selector getSelector(Object obj, String method) {* I& a$ S4 O3 \
Selector sel;
) w0 e* }( \: g% `$ W$ [ try {" y3 B. |7 V; \) X
sel = new Selector(obj.getClass(), method, false);
9 y! V2 d% L: i } catch (Exception e) {/ p& ^4 @ P/ s* D# g
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# S$ z7 r$ \$ K5 o l8 ^/ E + (obj.getClass()).getName() + ".");
6 A2 T; F) k1 Z- ^8 N System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( e; a" O7 U+ v0 i1 S$ [
System.err.println("The process will be terminated.");
7 A5 L. ]( t7 G2 t' _ System.exit(1);
' d* G$ ]& F% G return null;
8 n' ]) v5 w7 i }
- E7 J3 B& n. k. w return sel;* a, z1 m$ H @7 L6 [' ]* d: n" z
}) b* J8 K, q2 ?* r
} |