import swarm.Selector;4 k K7 g. b6 i( G- x
/ w* i+ t/ I( z) {4 i% H6 k6 A
public class SwarmUtils {
. k4 y3 z; Z/ ?9 e4 `) c public static Selector getSelector(String name, String method) { a! Z5 c) ], A+ @) J
Selector sel;4 ^6 S# c ~5 P+ ~; k3 S6 z) p
try {" {9 q7 a2 |% E2 G* ?+ p
sel = new Selector(Class.forName(name), method, false);
K$ M. R0 {" J( ]! ]4 h7 ~9 C8 ] } catch (Exception e) {+ _3 k+ g9 N, p* B
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
0 I( B( x- Z2 ], c1 G- R2 G System.err.println(name + "." + method + " returns " + e.getMessage());2 \% t4 B7 d8 A+ b& h* e8 N; A' |
System.err.println("The process will be terminated.");
6 `) K* @5 c- S! ? System.exit(1);
7 I& P3 D( f7 V% Y1 x ]% T return null;- M; W% q# p$ m# b
}
' j7 e* X- B5 ? b# k$ Y return sel;/ |- i* N7 R" U m1 {: m! z& q6 u
} |) }4 }- O1 J# {+ A
( ?" V# F% O" k; k/ p% F
public static Selector getSelector(Object obj, String method) {
9 b! O2 C0 B# }# ]0 e Selector sel;' ~4 A! ~3 U. L, d) u6 `2 i
try {
4 g& Q1 \, N" n J3 B sel = new Selector(obj.getClass(), method, false);. v1 r2 T) v+ n7 Z2 V! u' _
} catch (Exception e) {
% l, ]# j2 u0 m! ~- S+ }* w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ": j3 l0 N7 d9 l- D# g; N! r
+ (obj.getClass()).getName() + ".");
5 ~' U6 k9 J4 U$ x# J System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 D5 ~% S$ M$ k. Y. n System.err.println("The process will be terminated.");
- c- _$ _+ R+ ~/ s. s: `. u System.exit(1);/ }& a I7 \: h1 C3 U: ?
return null;; k! B( V+ ~" u; b4 v9 q/ Z
}0 n3 A6 W( }) P( _" `+ W
return sel;
2 o# d- Q; P8 m7 M7 X I/ P }
. B9 `. k+ a3 {8 z} |