import swarm.Selector;
, A& A1 |/ |4 a% g- W* S/ b
* t; F- N" H6 X% |1 l' K) hpublic class SwarmUtils {
! i5 z+ l' K* U public static Selector getSelector(String name, String method) {2 [) x: z( j$ N( [7 m( j9 T
Selector sel;
' r0 l) W+ b8 J+ I6 Z8 U try {
" c; a' l$ f2 } sel = new Selector(Class.forName(name), method, false);
% J& S% Y* I3 v$ S! D } catch (Exception e) {) H# e' |6 c, F7 B
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) f% b) z/ j8 }6 X( F+ k System.err.println(name + "." + method + " returns " + e.getMessage());4 ^/ V: H: k+ u* k
System.err.println("The process will be terminated.");$ M* j) \& K4 a. P
System.exit(1);
* K5 Q' [3 K# U9 i6 O1 v. w/ V return null;4 x/ A, R, _$ N* v! B/ b
}8 v" Y8 y: P" `% B/ b7 y0 {
return sel;3 V z$ @$ p- r: n: c6 K
}
( A8 D6 j0 |/ E* N0 V: O. J
1 F' ?( G/ _+ }1 O" x- F public static Selector getSelector(Object obj, String method) {7 Y) S- ]7 U3 q. L* T, z
Selector sel;
2 k. \( X* b6 ?7 u9 R. c try {+ M) C& B! Z2 S% Z8 ^
sel = new Selector(obj.getClass(), method, false);
3 D* \7 l4 T8 g; I } catch (Exception e) {
2 J6 ^6 b# ?4 U# d1 K System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "1 j W4 F% N6 l! ]! \% o9 u
+ (obj.getClass()).getName() + ".");' q: s- V5 K: U% A. }) i
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 _8 J1 ?5 b5 r+ M* h8 S) k; O9 w System.err.println("The process will be terminated.");
{9 C! n/ d2 U9 F+ {2 r$ J6 X System.exit(1);/ _" h; s9 T0 R: Q6 t- ^
return null;
, w X) l& F) f* f' T' P% y } |' A4 Y% S. k" c
return sel; y; m, s# \! W+ H+ p! h
}1 T8 B6 w N! D$ c5 O
} |