import swarm.Selector;- ~9 S" v' r( P+ ?8 A
1 P v9 n8 q- h+ B* a: Spublic class SwarmUtils {
* a Z5 g0 Q+ ?9 ?: l6 B7 } public static Selector getSelector(String name, String method) {3 n, j/ z9 s$ v# H. x& H, m0 Q, x
Selector sel;
' q* E# ]3 w% G. \, V4 y/ @ try {
% D3 o2 b* o, h8 \3 e- L sel = new Selector(Class.forName(name), method, false);
+ m( C1 w k9 b6 H* m D+ H } catch (Exception e) {3 }# N2 k3 \5 r- z- ^" c
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 E- G& Q- P* \5 S0 a# D
System.err.println(name + "." + method + " returns " + e.getMessage());
/ ~, {2 k3 F3 N System.err.println("The process will be terminated.");
0 [1 T6 L3 V2 V3 t, K System.exit(1);5 A1 Z& Y& `' ?
return null;9 ]- k! x$ y9 _7 w2 J K
}6 p) w' K) `- D- s, ~& a$ j
return sel;
' w: R+ M/ v$ t5 S3 T }
T w9 B, L( t, c$ Y3 @& Y* Y7 p; M# A
public static Selector getSelector(Object obj, String method) {$ V* ~* l# L3 ?+ l
Selector sel;; w1 w2 c" E7 c, h, H! E0 Y
try {
/ e6 v( V; K- H; b: ~1 G4 `* S sel = new Selector(obj.getClass(), method, false);7 m) ^$ W& K0 n2 ?! J
} catch (Exception e) {) t& b& J6 N B5 {
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") r0 S5 Q. U5 u- d; [/ {
+ (obj.getClass()).getName() + ".");; d9 h. V9 n. i: C
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) z: |2 b( p# O1 X3 ~8 m System.err.println("The process will be terminated."); V, ?$ ~3 A4 b' s
System.exit(1);
) L% V" T7 a% {. Q9 I& H N$ u1 R return null;; t% W8 t H# m$ `
}
! O: R# B& R* c$ d- X return sel;" m* v0 I" \% d9 D" d8 l
}
$ d `- Q4 a. T- }} |