import swarm.Selector;
; i) E: ]! B( l' P, Z$ u2 x! @8 N" v
public class SwarmUtils {" j' t3 D# x9 h5 ?; W
public static Selector getSelector(String name, String method) {3 `! K* S3 c% r" o) {4 A
Selector sel;
4 l& ^6 r7 \+ c' M try {
+ T8 S' L4 w, I8 v2 p$ e8 \5 { sel = new Selector(Class.forName(name), method, false);# [2 I6 ~& j2 t+ l$ Y
} catch (Exception e) {! M& T: C" M- T5 ?1 }! M* @
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");# I4 X- u3 ]6 e* }: B+ i
System.err.println(name + "." + method + " returns " + e.getMessage());4 f5 J, n4 r. S, G. J* x6 ]* |
System.err.println("The process will be terminated.");; ^# b& A. K: i1 r# C4 w
System.exit(1);0 }; {. b3 v3 ^3 [. P! O9 v. L9 d
return null;
- R, T. } e0 N% _1 o }
* }$ J7 \7 B3 e0 N! ~ return sel;
1 h% ~% x1 O7 [5 B3 T }
$ h" K* k! G+ v7 I- C$ Y
+ q& G5 p5 Y$ x4 I- U public static Selector getSelector(Object obj, String method) {
3 G6 K& h! L( P9 w$ B7 I [8 d Selector sel;7 c# [1 Q5 v7 v! Z
try {
- @+ v5 o9 x7 G2 P sel = new Selector(obj.getClass(), method, false);/ B( ~# O4 s; c$ m0 |- K1 i7 W
} catch (Exception e) {, I* Q7 j9 |0 v1 D1 e# f3 o
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ u+ V! {" N# C* q" c4 Y; K" Z. {3 T3 @
+ (obj.getClass()).getName() + ".");- }6 Y( J; ]" a: E# a0 x
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
& {7 x9 @7 }' O) T System.err.println("The process will be terminated.");
$ Q# i( X1 a6 f; c- _) j System.exit(1);/ _6 w. p$ n1 w7 ]3 k. d. S/ C
return null;
" N6 C( C7 S' `9 O. { }
2 X4 ?: R/ t2 V. }+ T return sel;
' o( G8 n/ V' h( Q5 C( x8 R$ U/ F }
6 G) R; C/ f' ~( ~} |