import swarm.Selector;# Q1 F3 y/ d2 T5 l- w( v
1 K/ w1 t6 }! M+ K+ f+ ~7 S1 U9 ~1 N% apublic class SwarmUtils {6 a; O ^$ ` h2 Y; \
public static Selector getSelector(String name, String method) {/ _. U5 ]2 x9 ^. Z
Selector sel;* S( _/ x) g; p- x+ u
try {; l' h6 X/ i9 E& }. y
sel = new Selector(Class.forName(name), method, false);
9 I& C: H, ^. G! S# y } catch (Exception e) {6 q4 F- m7 C+ O' R$ ~" B
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 a9 k# Y4 L- @0 P, Z
System.err.println(name + "." + method + " returns " + e.getMessage());
~ Q, t' T; J% N0 q/ H, E System.err.println("The process will be terminated.");1 x! ~7 k) ~4 O P8 ?8 N
System.exit(1);+ u, I3 |: h4 g- H
return null;4 j( N, \0 s r
}& S" {9 W$ y; C+ q8 x
return sel;9 ?! \* _9 e1 J" j
}1 V' J: a* g- J( c. \
. t. ?# J Y2 [+ F% F
public static Selector getSelector(Object obj, String method) {
* ?& w5 ]5 r; r7 n- v1 E1 ? Selector sel;% r# [$ H5 a" d$ d$ ~
try {
* ?' b% }# q% S' X sel = new Selector(obj.getClass(), method, false);: h) n2 G9 y. y7 F5 Z6 M
} catch (Exception e) {7 l3 u# h* C% _& G& t
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% R! {6 F$ O* T8 m2 j
+ (obj.getClass()).getName() + ".");, G: {9 h* P; ?, M2 C/ `
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 s4 h9 Q+ z) j6 R' i System.err.println("The process will be terminated.");
$ L) T) V$ P) A System.exit(1);
; r' z S$ f2 k# { return null;
& e4 v- y: O8 h5 T3 `( h }! ?+ g7 W H5 e& O8 ]
return sel;
, a# X/ E {- [. U6 M }# K1 O0 ^; Z7 v# p% i, c6 | t/ v
} |