import swarm.Selector;
! T0 ]# r" ]9 b$ K4 X; I
% }" v2 d; _3 c/ V# k4 L% Hpublic class SwarmUtils {0 |) t6 A7 {0 k
public static Selector getSelector(String name, String method) {
( s; Y X Y9 R$ O; d) r. X5 h Selector sel;
& }) Z% ]8 B# A4 ?1 q/ v/ S" M2 b try {
, [9 Y# I; e& ]+ ^ sel = new Selector(Class.forName(name), method, false);
9 F% m+ `& D& D: R/ p; l& w } catch (Exception e) {
2 A2 i, |0 t4 |9 c System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 n3 Y2 c6 _- ] j/ @/ ]1 w p& G$ o System.err.println(name + "." + method + " returns " + e.getMessage());. X c9 R: O+ G' Z4 i: x3 P
System.err.println("The process will be terminated.");
. H; w6 ~0 K: Z5 l! H' y7 Q System.exit(1);+ m( k6 m6 a: P8 x
return null;6 q) e! ?5 v' f4 b5 m
} ?6 R( g+ y2 m4 U0 M0 h& I G; V
return sel;4 D5 c' ~) s7 I7 i9 O/ u
}
; t% I- u: E4 J' z' j _+ U- @/ T7 Q
public static Selector getSelector(Object obj, String method) {
6 F3 n6 x5 t2 }3 K. m Selector sel;
, R7 u1 m! O" [7 n8 R try {- F8 N3 Y1 V9 ~
sel = new Selector(obj.getClass(), method, false);
2 V% Q% i. h( o- C- H } catch (Exception e) {
! n- @: ^ r3 t( S# v! s8 [; H3 z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% ]- x& [, K: p+ f2 }, s + (obj.getClass()).getName() + ".");0 x0 N7 s2 l5 G' _6 Y& Z e
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 \. F5 z; V! o4 d
System.err.println("The process will be terminated.");# F8 U7 q3 Y) w
System.exit(1);
; Y, u1 u1 O0 q6 Y return null;
$ \ q( n' s ]0 F6 e: W: G. k }
& u: d# T6 I& V& a return sel;
! G$ X7 F2 `( D) H6 b2 N- d }
# @' {/ T* x' i0 Y+ I8 P2 ?) H} |