import swarm.Selector;
' u( j1 L' L7 K- C' |3 Y& {: R/ v. y& v$ q2 P7 ^6 t
public class SwarmUtils { w6 u/ k- u/ D! I# V
public static Selector getSelector(String name, String method) {
- \& t0 p1 f, \( ]- \ Selector sel;
5 R7 y% I1 V) _ try {7 }% D9 }8 q# M# K4 O2 {
sel = new Selector(Class.forName(name), method, false);$ T$ X' x! P& W8 ~
} catch (Exception e) {
. Z9 Q9 N( y4 E0 l; r2 @( e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* m1 f4 D; ~, M System.err.println(name + "." + method + " returns " + e.getMessage());
! h) {' @7 W+ j4 d+ V System.err.println("The process will be terminated.");) x3 }: g. @; K( C
System.exit(1);$ Z o( P, ^0 y6 d6 t m3 O( K
return null;; f+ ?2 t' i2 S8 u; E$ A% i
}
0 M% U( e1 `$ \5 N" V6 t8 ?3 P return sel;; [ c4 D6 f3 |% g- V* P
}8 N% w- }5 b( F. \% _7 n' j
( D" h, N, r$ Y5 @/ E* R
public static Selector getSelector(Object obj, String method) {
3 Z" e9 w$ a! { Selector sel;- k+ X% v7 {5 B
try {
4 @' f6 @$ l8 k) x R sel = new Selector(obj.getClass(), method, false);& z4 @! ^' M) k& M) G
} catch (Exception e) {- R9 A9 _7 D: S
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
5 e; Y& b* v, |! n + (obj.getClass()).getName() + ".");$ t7 Z- C4 P% I' \' K( k2 N$ I! X
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" f1 w; c' B; S l3 G% J2 a
System.err.println("The process will be terminated.");
) k0 Z. Y- z0 p' D/ {) @5 e System.exit(1);
4 X; T/ b c$ P6 x9 Y& }' j1 v return null;
! e7 D+ A; S; D- c9 r }; w& H( X$ i* C' c* L# s5 s+ Y
return sel;
5 G/ E; H! r" r }8 W. _4 A# K4 a" D5 I+ ^8 u
} |