import swarm.Selector; A: o! O! s4 P
, _9 x7 b' H1 L S1 Opublic class SwarmUtils {6 F6 _7 X- A4 w- }9 x# N
public static Selector getSelector(String name, String method) {9 O# d& h% b9 U
Selector sel;" Y: Z4 |- [! d
try {
7 L6 W$ ?+ F+ S4 D sel = new Selector(Class.forName(name), method, false);: q; W- d/ ~* s
} catch (Exception e) {
/ o p( t7 c0 i9 S/ w5 X System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& i6 D0 n5 j) B, N' }- b' X
System.err.println(name + "." + method + " returns " + e.getMessage());
4 Z: s, A) ~8 J1 H: Y: e System.err.println("The process will be terminated.");! A- m7 B% H7 U. x: M
System.exit(1);7 Z" k8 L: d7 B) c4 R, t- z: u {
return null;( R' X+ T# Q, |6 B6 O
}( H! G" u- |; f, I4 X, d
return sel;
, x P; g! c) w5 V$ p5 f3 k" { }
: O/ I& z$ V- [ e7 k: C+ L! N6 ^4 j
, U$ i2 Y/ z" ]. `: d* y7 Q y public static Selector getSelector(Object obj, String method) {
2 E' C5 B0 J+ v/ o3 S8 \ Selector sel;) X! u K- |4 b# `& O6 f' ]& M
try {, s0 ^- C9 u' p3 f r3 A% Q8 T
sel = new Selector(obj.getClass(), method, false);
' ~) a/ [3 X. f% z } catch (Exception e) {
2 @; x h. n2 n# @) B9 ?# i System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& Z: u1 u) ^2 v+ y/ K- L. F + (obj.getClass()).getName() + ".");6 i) w* N+ q7 j+ g7 F- @$ k
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* ^ Q$ M, R. y* h
System.err.println("The process will be terminated.");
& M5 J6 z8 } i; x+ t& Z System.exit(1);
- F: h r) G" k5 q return null;
+ U8 p& D% `! X+ |6 D* y }
2 ?1 n- G# ?8 K: w) R return sel;
, _$ b0 _8 }/ X n) a9 \ }
" |. y8 _0 v; i7 {) k. E} |