import swarm.Selector;, J$ `8 K8 n" _
3 F# E/ U5 Z2 m
public class SwarmUtils {; @& r/ j: y; S, {. G: W; j
public static Selector getSelector(String name, String method) {5 G. [% [$ D4 S; n; m
Selector sel;4 r# x3 e3 V- f8 W; Q
try {
& ~; }9 [( N7 U sel = new Selector(Class.forName(name), method, false);
4 k2 @2 T& i) B# f2 J/ D } catch (Exception e) {8 e' j1 W9 G8 V5 M/ o7 p
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 p! W1 O/ L$ s' A% I System.err.println(name + "." + method + " returns " + e.getMessage());+ r) ~8 k' D1 D2 ~: ~
System.err.println("The process will be terminated.");
! M2 T& V- _, F, H7 r2 q: r System.exit(1);( {4 |$ J- H: B5 T2 _
return null;
9 n* [/ T8 v' P }
9 g" V. |, c6 r. t return sel;
5 o/ [0 s4 @0 p" d9 Z+ H; S3 ]: z }- n0 B( p: _. ~3 m& u* o
* o) h. H' D( r5 j# r e. m public static Selector getSelector(Object obj, String method) {
+ @4 H$ Z# u X/ X* q# M2 Q Selector sel;
5 Q4 A$ w! s) h, U try {
( i1 m) H# m3 T) s sel = new Selector(obj.getClass(), method, false);" V2 C' ]! d" j1 [. W; f5 E) p
} catch (Exception e) {" `7 A+ b6 j3 z0 x1 r: ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! l% ]8 P: _/ n) o) e + (obj.getClass()).getName() + ".");/ B' q. X& X! n, s( H0 A) `2 S
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: S6 u& C1 e% s System.err.println("The process will be terminated.");
+ j. n6 N3 l. T: f4 |6 `9 H- g System.exit(1);
8 U& a; v4 X8 ~ return null;
9 u( n0 w ]& H o- S } \" n8 M% u' v- T7 [! b( _. Y* H& r
return sel;
& ]5 @! e+ ^) o# f9 m }0 @7 f5 \* s1 Q1 ]+ u
} |