import swarm.Selector;. `# J: r" g$ U; n
. |, B( R, Y. R2 h+ Q _/ G! H! V2 s
public class SwarmUtils {
3 h7 O+ {5 Z7 a8 m* H" {7 s4 }& F/ a; N public static Selector getSelector(String name, String method) {4 [! f% X \* [ i! i
Selector sel;
8 F8 b1 d% f$ X% v! G0 }, K0 K$ p try {& e! M& q8 i9 f ^- b
sel = new Selector(Class.forName(name), method, false);
( h( P2 N+ j" I# ^4 R, t4 e0 ` } catch (Exception e) {: O) i8 \& h. y3 t
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" C% Z! q! C( q1 c System.err.println(name + "." + method + " returns " + e.getMessage());
4 ]2 f+ ]. j* V" j0 u0 T, i( M System.err.println("The process will be terminated.");
; B7 t, ^6 N9 j+ g/ X w System.exit(1);
, ~* ~+ X% g: @- x: @ return null;
- I1 r: \3 j+ w+ O( Q/ }) P8 o }$ F6 g( x5 {6 _) ~
return sel;
% Y0 V1 F' J2 h8 u9 X# w: s }2 s3 L, Q) i# z7 s' p
8 U. \* a2 e) D- V! t( Y' S0 Z public static Selector getSelector(Object obj, String method) {
6 U4 G$ r. T3 `" Z c- \& s. s& g0 x Selector sel;8 S( c) h8 p! k: v/ l% w
try {% m l& H1 f/ m7 X6 D9 }$ a* l
sel = new Selector(obj.getClass(), method, false);
: L- j7 s1 K$ z% Z0 ?2 v5 W } catch (Exception e) {
3 C4 L2 o3 p8 A5 J( a C# d8 m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ W/ L' O! z! ~( S+ D" H- C3 { + (obj.getClass()).getName() + ".");$ w- l" Z% R" e, U/ W9 q \
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
& Y* P6 g0 l+ ~/ C' |% x System.err.println("The process will be terminated.");
- }! V% u( N" |1 u8 w3 ?$ ` System.exit(1);! u4 q- c" N H. B, U3 B
return null;3 ?: ^, i6 H1 p' Y4 E+ s# `
}; h) Q+ E/ v) E) o2 L, `7 B1 u, f
return sel;2 j" S) ~6 r: j: Q1 i; X! u
}$ R. A# J; m: f/ I$ E8 V( j
} |