import swarm.Selector;
! T3 r- q1 [3 N) y6 C9 B& H0 v* O
5 k, y) r9 g" D( }public class SwarmUtils {
. E+ {% @* T; q' l) E public static Selector getSelector(String name, String method) { v3 F0 R7 p$ o" C2 ? N+ x1 w
Selector sel;0 o" n0 D* f; N" ]+ y: w1 y
try {, D2 x2 ^$ v9 c1 ?. W! g8 W! |
sel = new Selector(Class.forName(name), method, false);
$ @& b$ ?& p8 P# ?3 k% T } catch (Exception e) {/ _6 P6 S' P# Z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* h6 n* L- Z0 U/ v System.err.println(name + "." + method + " returns " + e.getMessage());
" `9 i+ D) h4 R2 g2 Q- E2 W" s9 s System.err.println("The process will be terminated.");
( y# B0 _3 r j S$ }7 y K$ M System.exit(1);
# ^* G6 L9 b9 {3 ]; f return null;8 V4 z& a$ H8 k! l6 P! L4 E- n
}
/ _2 q( c9 |2 e8 d$ q7 l3 {0 B) ^: \) p return sel;
& o4 P0 f3 U6 H& q% i }
) n+ y! G4 @. ^8 d. R( c) ]
& I2 N* N* d+ f$ \ public static Selector getSelector(Object obj, String method) {( `% q; M8 q9 P$ q- V1 L
Selector sel;7 c2 n W% S4 } J" }% g/ x
try {
; E1 u$ W4 n4 z- D sel = new Selector(obj.getClass(), method, false);
! K ^: x! E- n3 x } catch (Exception e) {
# L* D1 G* |6 w3 }5 c System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 Y! t8 k2 k1 \4 z5 m4 o7 E + (obj.getClass()).getName() + ".");! a/ _ z$ k# q4 O+ a
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ H0 V$ n0 \3 q% u2 L a0 b
System.err.println("The process will be terminated.");
& Z# O# u( i+ s4 W* \, | System.exit(1);
5 b: |6 l1 Z0 b' A" y+ [0 K. H" V return null;
1 G: `- r7 @& O" m( U, l- `# a }" ^ G' Z6 Y6 H: @: |& L5 N
return sel;9 C. Z: u) j6 y8 U& Q+ q5 b
}& D+ C. v" E9 S; a2 X
} |