import swarm.Selector;, q% O8 |4 r$ W. E" P! V
; P% D1 J t" d% l
public class SwarmUtils { V3 f1 L9 }+ @3 g9 S# P
public static Selector getSelector(String name, String method) {
2 J/ {' H) Q4 p8 R, o; d0 ]* a; {0 | Selector sel;
3 R& z- [2 Q% Q5 D j' G. E; W try {# Y' |8 K/ n& n2 N
sel = new Selector(Class.forName(name), method, false);
) M0 I9 w, [& X" A( p( ~; V } catch (Exception e) {
1 B! @) Z+ \% r' z z& A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! y/ ]* S; _3 Y9 L System.err.println(name + "." + method + " returns " + e.getMessage());
( D; A8 n5 u R' D3 S1 f* K: g System.err.println("The process will be terminated.");
5 }' P( p4 |, z System.exit(1);
& Y- v; _, a9 o0 ~, x* X return null;" M# a. x3 i: |6 `' v8 ^% t
}6 X5 ~ l3 V5 L, J0 g Q/ B, H
return sel;* f' Z. S3 s- y. n& C! P3 V
}
/ I& v( c% C! \: ~) K8 G' k" R/ `4 U! L
public static Selector getSelector(Object obj, String method) {
0 H# G# z$ X% z7 Q. ~3 N$ p Selector sel;4 m" r- t* |( d2 M
try {# L3 @# r5 J) y, i
sel = new Selector(obj.getClass(), method, false);
0 l) [' ?; W4 l/ f3 L } catch (Exception e) {
/ s% Y+ r T) w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 Y6 ]+ k0 |9 p5 K' z. }3 [6 g + (obj.getClass()).getName() + ".");$ S* G& j' c6 Y+ w _9 V
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. W1 g8 d* {+ G: b/ R' A9 H ?
System.err.println("The process will be terminated.");
! a+ P' M+ d) U System.exit(1);7 I' d# ?6 P0 B. Q
return null;
0 C* z+ s) v: Z2 H5 _5 g }
( x) s8 G. x% A/ M4 D8 E return sel;
! ]5 c7 G1 l: Q" }6 b } n7 m: h! z) D. ~ U
} |