import swarm.Selector;, x5 Z$ b" h/ f/ Z+ T% r
# w' b( j4 X& L- M% E
public class SwarmUtils {+ U" {( i& r( P4 P9 I6 C" \
public static Selector getSelector(String name, String method) {
4 X; Z0 D. `4 Z4 D7 j: o8 M Selector sel;( h/ L& n0 Z7 u$ M
try {
+ Q* ~! l7 V7 k+ d# {4 W2 O sel = new Selector(Class.forName(name), method, false);" e1 c2 b% j% T. R1 h5 A+ {- w
} catch (Exception e) {
( \( T# B( f' c i+ m" n System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 k; }6 ]3 `; ]5 H* ^7 e$ ?7 c/ ~' `
System.err.println(name + "." + method + " returns " + e.getMessage());
! u2 A. E9 [2 ~( N! ~ System.err.println("The process will be terminated.");
- H; Q0 J% j }" G' j( M System.exit(1);& e3 J) U D; W5 D7 P, O) K
return null;
% x0 W1 [3 Q/ k A" A( r+ Q+ x. O }
3 i+ T/ u( \' N' Q return sel;- y; g# w2 A$ v! s
}
) f! V0 i' v7 n' o
: m* y( N6 h& q9 X public static Selector getSelector(Object obj, String method) {2 ^6 M% D& q7 }) N1 a3 b
Selector sel;
- u* l2 Q( T/ j# F" T% q/ C try {
' W0 d+ v4 i9 d* x sel = new Selector(obj.getClass(), method, false);
6 g z' ?4 C7 B8 C! v( b } catch (Exception e) {& C c9 v/ B: j
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( F& a' M; T5 r4 G9 j/ g& j + (obj.getClass()).getName() + ".");+ f5 L7 U; u' M; k% [' ~
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# W% u0 N/ A2 Q D5 \: t! {- ]
System.err.println("The process will be terminated.");
/ S5 S- W9 C3 @2 u/ U System.exit(1);
; w( B2 {5 K! ^$ v9 N return null;6 l8 B, f3 E: R/ @* l- B9 V
}: ]& V8 l/ Z: O' ?. K
return sel;
0 W' b* i7 K2 |8 p+ {, N. z3 f } {+ w! @" `9 e4 b0 Q
} |