import swarm.Selector;8 U* Q1 E5 K7 u
7 o; [, y# f+ U7 I' Z8 A1 O2 Ypublic class SwarmUtils {3 x; J* Q8 g* L2 n7 ]5 p) D" v
public static Selector getSelector(String name, String method) {" c- X( X% {. K! {$ d
Selector sel;! ]4 E+ `! s- `5 U, M6 H% p
try {
- ~4 `+ @: U# b5 L" ] sel = new Selector(Class.forName(name), method, false);
p$ a* a, R( p0 {* H( H } catch (Exception e) {
: b& e/ u4 ^3 Z, j System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% ^0 P% `- p8 E& N# F1 h2 h8 h System.err.println(name + "." + method + " returns " + e.getMessage());( D% Q& N9 z% s6 H) l/ ~
System.err.println("The process will be terminated.");9 M. _& B% `. Y
System.exit(1);" x; Q6 m) m, k' A" x4 |! u; B
return null;
0 I5 Q6 I5 \6 u9 H0 {/ V }
0 x* I: m: N( H- X T: ? return sel;( L5 F9 J+ u" b* L6 \8 W
}9 ?$ S* ~# `, k. ]8 `
; Z0 a6 w. S9 I8 D8 A; t$ E* {
public static Selector getSelector(Object obj, String method) {4 v" E" _: ^% s% O# S3 g
Selector sel;
! Y; F! x8 W# l0 Z2 y- u try {1 M6 M, z6 U; n& N
sel = new Selector(obj.getClass(), method, false);$ z2 `8 R6 M) g0 t* y6 M8 B7 Y
} catch (Exception e) {
; ?6 l" K8 p9 x% K, s! l' M System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ V+ H3 q% G8 o: x( e* L. u" ]! E
+ (obj.getClass()).getName() + ".");+ s1 }# [- M4 P) i6 g4 G
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());6 `3 N3 G' ?" u$ f
System.err.println("The process will be terminated.");
+ Y3 a# e% ~; H! k0 m. X: K5 n System.exit(1);
) T2 K- Y; {; S( { return null;
$ t3 M7 t7 m& x }- `/ L. ~1 v7 h* B( S
return sel;
C$ [6 c! K% F' `" K# c9 ^5 a }7 E4 R; ?1 `1 B, j3 S. D; L: @! w
} |