import swarm.Selector;% U: x' k$ J2 Z$ Q' m: B
0 n; y2 G7 a/ f" N' i- Y) cpublic class SwarmUtils {! m! q5 ^1 ~0 {. K: F: I& Z
public static Selector getSelector(String name, String method) {
! d( Q/ R- k6 K3 W) `" }& h Selector sel;# W+ i$ u9 H1 e, k5 C
try {1 B3 h T% v$ S9 x' M) _
sel = new Selector(Class.forName(name), method, false);% V( x1 E M% S6 R- m, A+ a
} catch (Exception e) {: u- c2 |; q, A3 l v
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% ~6 M, j& P6 m' b* O System.err.println(name + "." + method + " returns " + e.getMessage());
+ ?. o; ]3 [- C, _" |; f System.err.println("The process will be terminated.");3 R, V$ B1 b9 Y
System.exit(1);* k$ _$ J7 l6 C& U% t
return null;
9 M7 m/ i+ q- ~/ s; }" K }
; V# e) o- T% |: c0 A, w5 i return sel;9 U# b6 r! m/ ?5 o
}5 p6 ~& G p E& r& C9 o2 ?
5 ?$ m- e; X1 I2 x. F$ m( ]
public static Selector getSelector(Object obj, String method) {
& ~, E2 a& M; J Selector sel;
8 B, I( g- c3 a; o, S7 v try {4 C# C8 Q; {1 c$ o# d
sel = new Selector(obj.getClass(), method, false);/ S" s& P1 B3 k7 J2 S$ l# ~% j' a9 Y
} catch (Exception e) {
) b/ G# c# c) g8 h% H4 I System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 G; d p2 S1 \, h. m2 M + (obj.getClass()).getName() + ".");
% l3 G% T7 D% z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' R- v) [8 b% C J. c" v System.err.println("The process will be terminated.");
e5 W1 I8 C( g4 d( _) x' o System.exit(1);6 v1 U. k! U( D- L7 z9 a# o- ? G
return null;
; C$ c0 F9 n9 u* W6 B7 u }
+ I$ q) g1 s3 x+ s# e return sel;
! m9 e* k$ v6 a1 L" y0 P/ p }
* N g- j5 ?# o6 w4 }7 }0 R; p7 h& a3 m8 R} |