import swarm.Selector;5 l' ~: M0 K8 i6 ]2 j& j
' d3 D A+ K5 [7 a! x
public class SwarmUtils {
! u r1 S4 V, ]" O! K% } public static Selector getSelector(String name, String method) {
' Z8 v2 m2 m& V+ p9 @& l Selector sel;
; I% G& o2 v$ ^4 K, J* ? try {
3 r6 E8 W) \. x! ~ sel = new Selector(Class.forName(name), method, false);# m7 ?2 Z; J) e' l/ b
} catch (Exception e) {8 v- h3 T; R2 s5 ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 I2 t- s8 H- p! |' ]1 C1 h
System.err.println(name + "." + method + " returns " + e.getMessage());
4 [+ ?5 m' a' j R: T+ P V System.err.println("The process will be terminated.");
. S* e2 C( Y, k; V) `+ o7 Y System.exit(1);
. D b9 Y0 z' @7 i: n return null;
' O* b* j4 a6 L/ `+ K0 Z6 u$ H }! ?- o! S4 T: V/ i) Q, Y+ k
return sel;
& R. \; e4 f. |, U }
9 O# Z" ?4 q) ], y1 K8 d- _! s
# H2 O9 J0 B1 x/ J public static Selector getSelector(Object obj, String method) {
: |9 U$ ~0 j% b4 F$ Q! G3 f0 y Selector sel;+ K- @- ~+ |: E. |9 }
try { p$ X L2 P/ r6 O! B% M
sel = new Selector(obj.getClass(), method, false);
2 X. n" e1 A: j' J& w9 x } catch (Exception e) {& c! `- L( g$ X5 ~ w
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 d# V, a: F8 N# c$ F2 { I
+ (obj.getClass()).getName() + ".");: \* O `; C6 C- ?% u+ h
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 }! ^3 X# z/ S b. j# |
System.err.println("The process will be terminated.");+ r) @; o6 o. z/ j" N6 u+ D
System.exit(1);! q3 M/ Y6 e: o$ y2 u
return null;; u0 x4 @- V) g- S1 `' B7 W
}
5 q8 b! q8 ^" H6 U7 s) X return sel;) h, \' c# C X6 `
}1 @: y, i% O8 p X- g B/ Y# Z/ l
} |