import swarm.Selector;
/ q4 c+ W, ^9 E( h! c, @( A1 B* z
" W; T* o) o; s/ U( R9 r& d* ^- vpublic class SwarmUtils {
( j( L/ m8 ~7 T R" H) K public static Selector getSelector(String name, String method) {, |2 Q2 h% U4 B% C* V
Selector sel;1 G m+ j* M! ?: f; Q8 K
try {
5 c8 ~( @" ]$ P4 j sel = new Selector(Class.forName(name), method, false);) p$ Z2 H& r5 l. d4 `
} catch (Exception e) {! n2 i2 V) W; v+ v0 T6 C
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");8 I7 ^& V9 o8 T; v# q
System.err.println(name + "." + method + " returns " + e.getMessage());# z4 M: x) ?$ g" t0 ]
System.err.println("The process will be terminated."); x) \, r- z3 W6 j& A, R/ q
System.exit(1);
8 t+ V$ p- I# q) o return null;5 S- O* p) o A) H
}
1 D2 Z6 G, {9 u( g" w return sel;6 ~8 I( Z# t- n% R
}
8 R( @2 B4 i! O- T$ j2 q( p- i
! S" F" `) r. b/ U public static Selector getSelector(Object obj, String method) {
% l+ w$ b( p% |0 J. o4 y Selector sel;
7 a! t3 Q& W' C8 ]2 ~" {7 z" H try {
4 @$ j3 I W; y$ E) h sel = new Selector(obj.getClass(), method, false);
8 U( k- T. P4 T: U$ w3 u/ f } catch (Exception e) {( c, A5 s2 ^5 Y' F8 q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 \' K! i* W0 ?' e8 p9 c + (obj.getClass()).getName() + ".");
. o) \0 x b2 `9 |0 V: D System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! x$ h3 Y6 x9 \6 F- V
System.err.println("The process will be terminated.");
5 ~4 e# R# Z X- J System.exit(1);, G, H+ C5 I. A7 e3 t
return null;3 |: I6 v- y8 z6 y
}
* \; [% \# T3 U: K: B* Z$ S return sel;
6 l, I' x1 \8 W, J6 R2 ~% i' c8 ^+ b }. E" k- T0 `1 I E% L. S
} |