import swarm.Selector;
4 o# B0 p) ^: `* d0 m
: I; G$ ^$ S+ e a1 N4 J$ Ppublic class SwarmUtils {& U3 [* |, X; `# _1 a
public static Selector getSelector(String name, String method) {
) U+ a& k5 h! Y, n9 ^" n* q5 R Selector sel;( b4 r; s+ j7 ^! z
try {
4 n! c& O6 ?# F4 i- r2 X sel = new Selector(Class.forName(name), method, false);8 P9 U% w. Y4 t7 N
} catch (Exception e) {' E" k) \) q8 D9 j
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( Q5 `$ w8 a% ]+ A4 {
System.err.println(name + "." + method + " returns " + e.getMessage());8 D( S" n, n' S% S
System.err.println("The process will be terminated.");8 S( H/ ~4 n* S* t$ }: K1 a
System.exit(1);
& i/ C( l, _7 ^; N7 P* U return null;, I3 Z+ F; Y# x
}
* K6 i5 a3 s! [# v. q2 X) o( F return sel;5 d9 b$ w9 B B8 R6 r
}
M4 A8 d, U+ e3 L8 D3 r& I. d
: V: g! z7 E0 | public static Selector getSelector(Object obj, String method) {
. D# A4 u5 r" u+ ~) }! M- n Selector sel;9 U) K: ]( x! x0 K" z
try {
7 _& L& X& B( j sel = new Selector(obj.getClass(), method, false);3 ~4 X$ |( h% @% n/ t
} catch (Exception e) {
; [' n6 X" N3 D+ q, X: C C System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 j) [+ u2 z( C5 V+ x- g/ }' ? + (obj.getClass()).getName() + ".");8 h' c, r4 Q$ C/ N. E4 n
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
3 F! r2 w: M, g0 \ System.err.println("The process will be terminated.");2 U# A% B# _" X
System.exit(1);
6 ]- k! W% ^6 Y return null;
9 _+ ^4 W3 u }/ ^* W }+ p8 F, e/ z, t0 n8 U
return sel;
2 R) Z8 u# q5 d k7 g }4 b2 Y- k& |, J. r5 K* D+ G1 U
} |