import swarm.Selector;
6 K9 L, ]& [' e0 A$ i1 n3 o! A5 H6 \; D" Z1 Y$ W' @2 M1 O- s# I1 u
public class SwarmUtils {- i& ^3 C5 }3 R
public static Selector getSelector(String name, String method) {
& L6 a6 Y# k6 N- B$ k Selector sel;# t6 m1 b/ l" {
try {
3 [0 ]" l3 A: r M7 G2 D7 P8 D sel = new Selector(Class.forName(name), method, false);
# G2 X) f" s2 F1 R7 M0 v/ W } catch (Exception e) {
& ?% @% b, z4 k2 u: Y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) P7 j) a+ j0 ~/ O System.err.println(name + "." + method + " returns " + e.getMessage());5 j* r8 R8 }3 v) V! V
System.err.println("The process will be terminated.");
& D- g3 j6 G' L( H% M6 ` System.exit(1);
8 {3 S$ `$ u( k* h% }$ Y# `$ R return null;
7 J8 T; Y/ ~% q0 E& b# Z }
. i* t9 K M7 V: K# T return sel;
' Y8 w' G g2 k% o; _+ _1 q1 b }5 T" f" @5 r# Y2 a' G4 l
$ X( N4 v+ W$ [! V2 B' }/ l+ h public static Selector getSelector(Object obj, String method) {' U, B! f: v8 Z0 b
Selector sel;
" R. C9 N$ w* v" I0 ]$ e try {
( E. u% v* b# j6 O/ ^& u+ C6 m sel = new Selector(obj.getClass(), method, false);5 J3 p1 ^; _0 s. n& c) C) n& y
} catch (Exception e) {
/ S; ~1 z6 Q; _' B8 W System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 P4 Z0 r6 N5 n7 G! o
+ (obj.getClass()).getName() + ".");
4 y! `8 S9 r% \ X$ y" D1 P System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ V& m8 T7 F" y! v j System.err.println("The process will be terminated.");
. u5 V9 Q' v7 B4 x8 q/ Z- v; a System.exit(1);1 `, @2 n' N+ e( W
return null;6 ^1 ]% n# k: g0 V
}! ]: h+ B3 o) p, d9 N% Z
return sel;
$ G, b& L/ J r0 I( E# b7 {# t }
% y. `7 @, W) {: h} |