import swarm.Selector; W( x" F" h. d
/ Y+ J, {, O- N$ m: P; S2 r! s
public class SwarmUtils {8 r3 t) F& _, d& I
public static Selector getSelector(String name, String method) {9 ^6 j0 ^3 n" g2 g6 `: d0 U J$ t4 T
Selector sel;
- Q/ r5 h! ?3 G try {
5 l7 _5 Q: d. F' R" E4 r8 T& Z sel = new Selector(Class.forName(name), method, false);& m# x" w5 A) @0 N r7 t
} catch (Exception e) {
7 u! ?: e1 c# G( F( o2 o6 n System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 S& Y% b8 X7 y/ ~$ W3 T$ e System.err.println(name + "." + method + " returns " + e.getMessage());
3 @# A( o6 A; u# B/ ]; T! } System.err.println("The process will be terminated.");' I/ _$ |& t: ~# f0 ~/ F
System.exit(1);0 u2 Z6 ]1 B( w- N4 M/ S1 J- ?( w5 g
return null;& T* F" X* f1 S% u
}- b8 {2 w8 P8 T% Y. b3 \ T
return sel;/ Z. g9 S# x: N. f: U5 A( A; A8 c
}
/ K7 R( Y7 q/ Z" T1 H! A9 S, \7 y1 X0 F+ I: d# |
public static Selector getSelector(Object obj, String method) {- t3 T# @7 {# U) s6 l+ S
Selector sel;6 }9 u+ C; x" p9 N* L/ p' K) W
try {& ^& E) ^2 w, N4 w, S( E9 }0 f
sel = new Selector(obj.getClass(), method, false);( f- U% b% X+ o
} catch (Exception e) {
( |0 X6 Z+ v& B3 D8 L+ |* ? System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ K1 D, i7 Q+ ?6 F1 Q9 F3 H + (obj.getClass()).getName() + ".");
6 d' O/ X5 Q3 f* |; q System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 x5 Q* ?4 E( i. I System.err.println("The process will be terminated.");* G6 p8 y* {+ ?; D/ P) t9 F
System.exit(1);
7 X U. W' Q$ r$ I* t! M return null;5 t' L6 ^$ U# Y7 [5 b0 U8 v
}
, W) E/ c+ \/ b. H* Z8 z return sel;
* S% n7 g- Y" j$ ?) p5 Y4 J }. j; y" {0 l6 s; z# ^6 @
} |