import swarm.Selector;8 |! x( X3 m% _' X$ t4 A; Z
( k+ u; E9 Y6 U: W3 o3 \public class SwarmUtils {
1 J; F' v# R$ ]7 P1 F+ b3 C public static Selector getSelector(String name, String method) {
+ \9 P1 m; N$ t4 U. `: [ Selector sel;
2 h2 |1 V$ Q6 W$ l+ A! F try {) f8 i6 J( D- Y
sel = new Selector(Class.forName(name), method, false);
! F$ t1 d! {" M8 T1 }+ y+ [ } catch (Exception e) {
! Z; R1 a2 v _ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( ~7 Q' K; p# G; T1 K v System.err.println(name + "." + method + " returns " + e.getMessage());
% ]; V7 Q$ Y/ H" \1 ` System.err.println("The process will be terminated.");. `& O5 y8 s% _$ e0 o9 f$ I; O- y8 C' X
System.exit(1);( d$ k0 i- z4 V! G5 q
return null;
& ]% q* g) T* }' N& s+ f }
3 p: K- @+ w+ I+ h/ V return sel;: |& Z6 V: _' i; W
}
7 v* B# P8 W& a4 ~- ~
. `7 k- r3 j; X" W% H+ m1 F public static Selector getSelector(Object obj, String method) {
{! F/ [% y2 M/ I- S Selector sel;
* g8 U( w1 x' d) ? try {9 |- k s/ Y/ B/ B: p
sel = new Selector(obj.getClass(), method, false);
+ l1 B" r8 Q8 Q. _ } catch (Exception e) {
6 i! L/ T7 s' R4 A( p$ I7 M System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
, @' Q. z ]+ ? + (obj.getClass()).getName() + ".");
( ~; T' u5 E* J/ X2 K, T) G m$ X System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: Z* i, e8 W0 D# {" l3 W System.err.println("The process will be terminated."); ~ l4 [5 l( [' o
System.exit(1);; C8 {0 X0 m* G7 ~7 k" l: `4 B: b! P
return null;
. i5 o2 M+ H; Q }1 n# K9 H) m- S& t. P c; k; U- j
return sel;
5 w# u8 @: b, G/ N; t% e# L }: R. U: D/ Q6 Y" n! K/ y: |* G: x
} |