import swarm.Selector;
& H$ ?/ Y3 Y" U; ~2 b' R$ X1 ]5 ?! x! P6 ?& a/ c' ^/ _ g* A
public class SwarmUtils {
. ] S. A: p7 }$ U3 Z public static Selector getSelector(String name, String method) {' y) N3 }* k, }* I" H# m1 C
Selector sel;6 F% ~) B) S+ i" ?
try {; A2 \4 `7 y; j6 k0 ?0 G3 s @$ x
sel = new Selector(Class.forName(name), method, false);! F; l+ n% l! p# k$ J% }
} catch (Exception e) {
1 V J1 Z7 V l/ n* {9 f System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 p3 @: M" T1 j* t
System.err.println(name + "." + method + " returns " + e.getMessage());
; \9 u f( T* @* P" b6 W System.err.println("The process will be terminated.");% X. X0 P5 F+ r. R3 n3 T4 Z* O% c
System.exit(1);
3 R/ ` Z) i* y3 O/ Y return null;$ `) y& s, a6 }3 R) T
}$ ~% L' \0 R9 T/ H; i" p$ L( @# x
return sel;
: O( [1 L& X1 N9 ?$ K( g3 ^* B }4 }& V- R3 V7 i/ I
1 g$ G9 R4 p' ~. E) J1 P public static Selector getSelector(Object obj, String method) {6 A/ @, z' U. B$ R! j$ ^7 `
Selector sel;0 D& r7 y* D r' `4 Z
try {
+ v) R' [: |) ~ sel = new Selector(obj.getClass(), method, false);+ t0 f& Q! ?4 k: _3 c
} catch (Exception e) {# u8 k$ w v+ u4 @# o7 O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 n! x5 I6 d/ f. G + (obj.getClass()).getName() + ".");
, s Z7 G! P3 w' G/ i" f1 P System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 W1 ~3 j. W6 A n
System.err.println("The process will be terminated.");
/ V" |; L* d6 H- \# r System.exit(1);
, Z/ y" H/ x* B7 U return null;
0 d4 k% i [" g, B' B7 C' q4 p }
0 N5 l0 \$ q& U# h- O3 i# e% F return sel;
& g' k# S E( `/ Z8 Q" A7 y, @ }
: e0 [7 r8 B4 r9 z" {} |