import swarm.Selector;
0 {* q5 c, L7 r$ d' N7 Y1 z' |5 Z0 a1 Z) h: r" B5 i$ _; t% e' b
public class SwarmUtils {
# M( f5 j1 a& I9 \: Q public static Selector getSelector(String name, String method) {
: D( [+ {( e% B6 m' X6 p Selector sel;8 q5 H9 K! H3 J4 W. i& `
try {( u4 n* l+ G( ~8 C) U, d. P
sel = new Selector(Class.forName(name), method, false);
0 T7 ]- X; y) k: R } catch (Exception e) {- \7 L1 r7 ~) o8 \3 B
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 Y. F5 _- E; B$ q$ d E- O3 u$ R System.err.println(name + "." + method + " returns " + e.getMessage());
& @5 M! j, z2 ? ]! C$ G$ K System.err.println("The process will be terminated.");, Q4 b2 B' H6 f" F0 P
System.exit(1);# h. S) g3 ~; E6 k
return null;: H+ d$ e0 ]% d( l: l3 S8 [0 }6 f
}
% U4 D1 g2 d/ {: _; L w+ s return sel;
8 G; `; }) `% s; R/ G* @& s }
! k+ h; _ K$ w0 \" |8 v7 m
" k% f) J( b$ @ public static Selector getSelector(Object obj, String method) {
& i' c6 f" M+ y% K- z Selector sel;/ H- T0 c) c; u
try {
1 S6 ~$ S3 r- E6 [4 O O sel = new Selector(obj.getClass(), method, false);) b5 l7 r3 r5 c) a: M
} catch (Exception e) {, A; e5 T$ A& l" |( H& d
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "* A: K" R* F N2 @5 v9 x: ^
+ (obj.getClass()).getName() + ".");) f/ z9 F+ N# m- g- f6 U1 ]7 j3 T
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ e3 T; Q1 i/ I$ j* w; Q, C System.err.println("The process will be terminated.");4 y$ @5 p& K6 j5 T. A
System.exit(1);
" R0 f' o( ?! a% E9 G return null;' q1 L( y8 w1 }" \9 z4 D: U7 v
}
2 J2 z- k1 P) z, c: e; N return sel;
5 k3 q" x) n$ V7 A. F: p8 C+ ` }
( J, D% E9 q, D! Q" z- r0 P} |