import swarm.Selector;
- P4 ^# g" ^; H: [2 }7 z' d: B2 Y K
public class SwarmUtils {
" r, r- P, o' r' f- b& B public static Selector getSelector(String name, String method) {
~' |, t2 Z1 |9 M5 y7 G7 i Selector sel;$ q4 Q4 n0 s3 {; J# L
try {
0 d/ V: t& I$ ?$ O o9 R' n! Z sel = new Selector(Class.forName(name), method, false);$ K1 n1 `3 O# X& b: [* S
} catch (Exception e) {1 d# ^# }: j8 ], ]6 h) A
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");1 S5 \5 h/ U2 x5 x6 }
System.err.println(name + "." + method + " returns " + e.getMessage());
0 L- S" B' o0 f System.err.println("The process will be terminated.");5 K/ N1 G! l5 ] K
System.exit(1);8 H9 {2 Z2 X) E! Q6 E; U
return null;
( d7 |5 r3 @0 X. R) d9 ~ }6 g! \7 o/ M- N2 k( t
return sel;4 o! i7 O1 I4 S d
}
! u, ~6 I1 D1 D9 F$ L( d, J; x; x6 ?7 b% V. \* l1 ]1 |* v
public static Selector getSelector(Object obj, String method) {5 L0 c- [9 q' ?5 A
Selector sel;
+ B. O7 V! _' B @" E C try {
5 H: A. m/ q/ j/ _ sel = new Selector(obj.getClass(), method, false);2 \% T% U9 U- B M( p# X" S
} catch (Exception e) {% Q# l8 U1 Z5 r* Z6 I6 ]: ?' ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
/ `2 X) ?+ W& Z4 K# Z8 B' j + (obj.getClass()).getName() + ".");" g" z. |+ P8 L8 U6 n8 k- r7 o, ]
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# Y' c0 U. P0 ?! e! @7 ^5 Y4 T System.err.println("The process will be terminated.");
1 F9 q( }+ y( f4 Q: r# p6 x System.exit(1);
* X+ d! O& Y% g7 D L& J return null;; k6 A S* C$ R) P2 o5 ^1 s% E
}: H: o# L3 `- p& B5 W+ ~4 ?- W
return sel;* y. U. q1 K0 M2 h1 x7 w
}6 [* m* l0 _+ V( ]
} |