import swarm.Selector;1 k; t4 D5 n% J* D: D1 `+ y; O3 W
3 z3 Q4 |# D' g) x, D+ [public class SwarmUtils {
& M& z) R, H! A public static Selector getSelector(String name, String method) {
( ]- [3 L+ b5 N0 }/ G Selector sel;4 g! K, n7 P `
try {
/ A A6 ~% v3 f, s3 ? sel = new Selector(Class.forName(name), method, false);* \$ j$ a* s. p: S( Z! B
} catch (Exception e) {% E7 j' P# I& V' J7 Z9 v; b% M5 b
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 q3 k( E- r7 A# [2 Q+ J0 p, Y K. R- V
System.err.println(name + "." + method + " returns " + e.getMessage());: W" Q3 B: r# y, l2 J
System.err.println("The process will be terminated.");$ N+ e0 T% }0 X
System.exit(1);
$ t4 O# T" ~% @) k. T return null;
, D" Q# W4 U( n3 f _8 U" t }
2 E1 I# U) D9 I, u return sel;
4 S7 |) q1 F5 G- d; N3 l }4 a( G# |+ ^3 c/ z
0 O% ?/ c1 n1 \, f& i public static Selector getSelector(Object obj, String method) {
1 F! ?. X/ a4 Z! q5 w; ^! s6 m; a+ ?- z- z Selector sel;) J. J v& X2 M: z
try {
3 N6 `. @3 W2 @7 l$ L0 y6 w$ n sel = new Selector(obj.getClass(), method, false);, o+ K3 x! t9 d
} catch (Exception e) {- _( m/ `+ G+ e {4 C2 B9 ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ I6 n, y3 J! ]& A% u
+ (obj.getClass()).getName() + ".");
$ u9 n% J' p& {" G System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) b$ ^- c* F! f* I
System.err.println("The process will be terminated.");* M) d. L. g0 O
System.exit(1);2 H+ I3 W3 \8 D
return null;
1 m) \* n) R( l4 r }# r8 K. R' o. ^ a, g ]6 k7 B$ o
return sel;
0 s1 z7 q4 G# b1 k8 u6 v- X& Q }6 J4 s- F1 m; K* @$ c5 t$ Z3 K
} |