import swarm.Selector;
3 p% c, o+ a: ^1 u: F# ]+ A$ d9 i1 V, q# E
public class SwarmUtils {) t! z2 D& e# n1 u7 p) u1 C' t8 f
public static Selector getSelector(String name, String method) {
' G% B5 G {. W Selector sel;
3 Y# H/ O' D. z7 y7 O try {0 b6 R! v# I7 o7 ^2 J% L" d
sel = new Selector(Class.forName(name), method, false);
; ~/ e8 ]# B3 I( U8 P0 S+ _- w } catch (Exception e) {9 b: x' U) a& w; l; q+ n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");$ c: }' U: |+ a3 }8 j4 z) W
System.err.println(name + "." + method + " returns " + e.getMessage());
' Y* E: X, G9 U! ]$ k4 h% t, O System.err.println("The process will be terminated.");9 y- H2 W3 G# x- T7 F+ X8 B
System.exit(1);
$ p# X( a3 g) N; R return null;. @" D, V1 m: |( a8 `7 k. ?% { f
}
1 X& ~* e0 ?1 P* o return sel;) M8 T1 I: r! w+ A5 G
}* O6 k5 T9 Z9 u" O# e
+ q# o; @) d/ ~) |7 ~' e: y& E
public static Selector getSelector(Object obj, String method) {" T4 f3 N# r+ K, v
Selector sel;9 D L; S. z4 S& ?7 W
try {
. ~0 i" j# b' ] sel = new Selector(obj.getClass(), method, false);
, ?. r! N, o& y6 E/ }0 ~5 u } catch (Exception e) {( Y3 \5 b9 i# N s; B7 X
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
n7 d) B) f& r; t + (obj.getClass()).getName() + ".");
0 S9 a: _; B% i) b9 O9 K System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 T* i V) H h0 z0 D) | System.err.println("The process will be terminated.");8 y, s! k1 e7 P s* [
System.exit(1);* ~; V# U# F/ I' J* F
return null;6 I8 Y2 [* _: g& z5 X9 A- l* |
}
9 I7 r1 n' o# N" d, u return sel;% _3 p+ c: x+ s p* q9 Y
}
) }% d9 y# W7 n} |