import swarm.Selector;5 ^* k: q- _- ^9 M" X D7 U
) O1 Y3 W A0 l( n7 \
public class SwarmUtils {
- s- E b7 H+ k: r; c& w# @7 t public static Selector getSelector(String name, String method) {' _8 T" s0 D' I5 E6 P- N
Selector sel;
* c' d6 W" t4 n) l1 l$ e try {
' v/ {5 k' E, M7 M' m f, } sel = new Selector(Class.forName(name), method, false);% D+ d+ s3 [0 ?
} catch (Exception e) {) ]7 a: N. }+ q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' S9 O9 c, Y; J6 W2 N) u1 P9 i System.err.println(name + "." + method + " returns " + e.getMessage());
1 P! `/ t+ ?. E& H* y System.err.println("The process will be terminated.");2 ~5 \* D% J2 A H- |
System.exit(1);* A* ^' ?- \9 N3 I& g% T q
return null;
! u2 l! @2 T: C* u1 D# B, q }
$ r; U# W$ x/ {4 s3 ?* Q return sel;5 ~0 f& [/ l" c S( {& v
}# Y, q! d1 U7 ?+ _, @; M& E( K) @
2 R5 o5 g9 o7 g) A. G: d public static Selector getSelector(Object obj, String method) {( g6 z) @; |9 P
Selector sel;
( l2 A, j- W$ @4 U try {
I1 S5 s, f$ J; B$ P! ~ sel = new Selector(obj.getClass(), method, false);
9 @8 X6 _* W7 X$ q8 U% T9 D" G } catch (Exception e) {
3 G( z' D" K8 |3 T* e/ V+ B System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ". r- Y, G8 }7 ~( U
+ (obj.getClass()).getName() + ".");% m* p, D: L! Q+ c/ S' E- x
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); p( M5 k6 E; o2 U7 }. K
System.err.println("The process will be terminated.");
" E: N8 x( P3 k System.exit(1);
q2 y6 r$ W9 [2 x% ^ return null;/ L" G+ s1 Z- L1 _' P
}
9 j; }+ L1 D- w9 Y% I return sel;
- l! n0 j2 v, ?; x) H% x( L }
* \$ _& q5 y6 ~} |