import swarm.Selector;
1 C0 \2 I. v* n4 }, h2 u; Z, E4 T' X/ p3 l
public class SwarmUtils {, E7 F7 ~6 K4 H' M& L9 u% e
public static Selector getSelector(String name, String method) {
' j6 n5 n) D+ Z) ?3 w6 D- I Selector sel;: L2 e; l- i6 I
try {9 @! H3 T, C7 V/ ^
sel = new Selector(Class.forName(name), method, false);' s( P" w* J' U; c& I' `
} catch (Exception e) {
2 w+ c: D* w9 [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& P# g* Q f/ l, Y$ w/ \7 u9 S System.err.println(name + "." + method + " returns " + e.getMessage());# L' g1 y- B" e p/ k' h
System.err.println("The process will be terminated.");
+ _ g8 {! h0 D4 h System.exit(1);; C/ q0 g* c/ F' ^0 y
return null;3 W$ n/ [! l3 H+ M% y
}% |$ q& t2 A: A3 t2 `0 J. y
return sel;! g" e" l& i% L9 {
}2 C0 _9 f5 D, v
4 L+ u, }# ]' y, A, T public static Selector getSelector(Object obj, String method) {# b U0 }' f1 f2 T$ Z: Z- T( Z/ D
Selector sel;
+ E$ R, s" S: E3 F5 P try {
) l. [& I& W4 F" @ sel = new Selector(obj.getClass(), method, false);& z' b- s6 u0 J8 L' V
} catch (Exception e) {6 S; D$ g g6 m7 R( q2 W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ". R; t4 h, y$ s4 ^5 @' G9 D
+ (obj.getClass()).getName() + ".");
# B) F+ [3 D. g7 y5 {9 m System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# Z+ ?, o& @' }( W% [3 O$ q System.err.println("The process will be terminated.");, @* r; G; ~6 k$ q. P
System.exit(1);
7 c8 z/ X' k2 D7 F$ K: Q/ d3 \" l return null;
3 G* ]* V# L8 `. D& N4 V }% c. A6 V+ \/ K! {8 w1 I+ Q
return sel;) [ C( P5 I0 j% |0 u) |2 N: K* x
}
" g* j \3 z l( I0 F} |