import swarm.Selector;0 R8 v& r* P/ ^" ?6 X; [ k
# ^! C) s0 q5 A, D5 `, U
public class SwarmUtils {
9 t% f4 n+ I7 [ public static Selector getSelector(String name, String method) {3 P( G8 l7 j: {5 [$ Y8 ?
Selector sel;% v6 o5 ~0 |' A5 q
try {0 _, N) P$ w) q+ l s5 a9 w
sel = new Selector(Class.forName(name), method, false);
9 X" |- l- [/ D* {: E/ s } catch (Exception e) {
; Y5 P8 U, H' r/ l0 z+ P3 F8 w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- p1 p- e B2 g* k5 Q
System.err.println(name + "." + method + " returns " + e.getMessage());
( J( Z" S" y" p System.err.println("The process will be terminated.");7 M9 I/ e ]7 D9 Z7 g0 P) T
System.exit(1);9 d1 c6 c/ n* L; v: l, F
return null;
) T% m1 F/ v+ l; z }% X( X& D4 A' d8 V
return sel;
& H, H- l! y) w$ c! Z }
7 H* k7 t' Z `7 {
& Q+ C. [' b6 q4 m public static Selector getSelector(Object obj, String method) {5 E$ C8 F0 Z! E* x9 F
Selector sel;
# o2 `0 ~8 i% D: q% k7 y' z! G2 K try {% Q& V- S8 F3 m( K/ {1 c0 I$ X; e
sel = new Selector(obj.getClass(), method, false);
) U2 ~) }5 Y$ B2 A9 ]- Q } catch (Exception e) {8 x# U3 A1 N. D, B, [) U
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 z7 ?, C* u* s* \ + (obj.getClass()).getName() + ".");
" n8 j) ?9 N" ^: q5 L2 w1 N4 Z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 _. `$ K9 N4 O, |* q System.err.println("The process will be terminated.");
6 P6 @1 I# W$ I& [ System.exit(1);6 H5 k1 f3 S9 w8 U: d
return null;; N0 S+ P. R5 ^+ h( A- Y
}
* {: d5 @0 v$ c4 w3 W+ c return sel;0 u6 I8 C: x6 M3 u! \5 d
}- F1 J+ O2 n, a! q. `% R1 d, b, n) A
} |