import swarm.Selector;0 e7 x! X/ s0 [, ^
% {* ?1 g2 t9 Rpublic class SwarmUtils {
% S- C7 I4 d3 C( y* K- x public static Selector getSelector(String name, String method) {
4 M! H& b! @) W: V# ? ?- H) C" L Selector sel;
' `5 d' k: S# ^8 {; t try {
3 D; d' f) _1 k8 B sel = new Selector(Class.forName(name), method, false);
5 h) X) F# R0 v# e O } catch (Exception e) {( o& @) p, W" D* O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" {+ M0 D3 D6 k8 x0 `! Z9 ` System.err.println(name + "." + method + " returns " + e.getMessage());
2 p# d' s8 ^! L8 L" u+ E1 T2 Z System.err.println("The process will be terminated.");6 Z9 v3 R2 k( f1 @) v
System.exit(1);1 b' P! v% M( ]7 q
return null;
6 ^. O7 h: F% l1 n }% h4 e- H$ H9 a$ v/ v
return sel;
( [7 }6 N% _% M7 H4 A } e3 x/ P" X5 @3 u7 Q; K
W1 T- _$ s& x1 R( J! [ public static Selector getSelector(Object obj, String method) {% m) @' A1 S( l3 s7 S
Selector sel;
, ~' x; j1 _4 u. K try {) k$ g4 S# @: e/ `- F+ b% J
sel = new Selector(obj.getClass(), method, false);
: ^# P+ \, O4 l, Y } catch (Exception e) {5 T" F$ S. @# y- v; M
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ D" L& N. N' G) o4 l + (obj.getClass()).getName() + ".");& d: c u* ?2 Z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
! l8 I) i2 E5 P( | s System.err.println("The process will be terminated.");
. u& c9 A8 u+ u) j8 r System.exit(1);
3 ?; v2 W( k4 ~$ I( _- j) A5 t% g return null;% O9 f% h- N s" p! w2 p
}* s+ F" S& ?+ d3 F; J' X1 M }+ j
return sel;% t! O e N" `; N: M }4 a" R, S
}
2 y- N3 M% @( n7 E6 J0 N) {} |