import swarm.Selector;
# `9 A! E4 y: I1 {. ]
( J0 V) C$ ?6 q, Ypublic class SwarmUtils {
6 V s, v6 \) x3 k+ q" H public static Selector getSelector(String name, String method) {" |+ j* }: S$ o# [
Selector sel;$ W8 b; E/ U: {7 D# ^1 M& z
try {
* I3 l6 G" E c! Q! M; P' A* k. y sel = new Selector(Class.forName(name), method, false);
1 `# l; j5 |" r; g- d" w3 N3 u } catch (Exception e) {+ {3 i4 Z o( W! r* V
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" U) _ w# e3 ]# }/ U$ u System.err.println(name + "." + method + " returns " + e.getMessage());" D k6 I& u9 \. m$ o
System.err.println("The process will be terminated.");; b# w! ?3 R+ Z& g
System.exit(1);
. R) y7 n: k. B. O8 `, U( ? return null;: D* p. Y& S* D3 O a$ Y s
}+ r" Y. Z e! j" l
return sel;# i( A1 O7 H* z% {' K+ [
}9 F7 @# B# o8 L: e
( Y7 b# y8 U* G5 S. T; t R4 O( y
public static Selector getSelector(Object obj, String method) {
, E! v, S% S9 r$ e& V Selector sel;7 h# F+ V( e/ }
try {
4 p: O9 A. ^' w5 @2 N3 h& Q/ O' f sel = new Selector(obj.getClass(), method, false);- Q5 a0 d5 j2 E, f/ ~3 D8 Q
} catch (Exception e) {
% n6 ^' O3 |' Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( P* r2 o1 ~" ]7 M* q" C* K! u + (obj.getClass()).getName() + ".");
- X% O) ^8 o9 [0 S System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 b* t9 q6 i/ f System.err.println("The process will be terminated.");8 H- S. c+ u' w1 T2 a
System.exit(1);
; p j; s! J `* Y- \, r9 } return null;! V4 }( G& s* }+ i2 g& b
} l5 e5 C) E: m; F$ i% N5 J( t
return sel;
/ g; Z- w2 G0 [4 e5 _ }- D0 v6 Z: j5 ~' G6 \6 m
} |