import swarm.Selector;
7 r5 v: z5 I5 N+ f3 u' d% S# Z( |( b7 l/ Y
public class SwarmUtils {5 n4 {" { c/ b. \$ e/ B" c
public static Selector getSelector(String name, String method) {( S9 X* N) I4 ~
Selector sel;
3 k; [1 d" o+ S; O7 c g6 \ try {
, J# ]3 \# ?" v5 X( n- | sel = new Selector(Class.forName(name), method, false);
8 {' x+ H9 M3 ~8 d } catch (Exception e) {
/ U0 t0 V: r! F8 |+ G8 E. G5 a System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 C3 @$ p* {0 i4 b2 K1 t* a System.err.println(name + "." + method + " returns " + e.getMessage());/ _& d# ]1 ~( E e+ r4 f. \
System.err.println("The process will be terminated.");
* w$ D' `" e" |6 f System.exit(1);0 X9 m: Q3 N4 w" k5 l, K; [9 J6 V
return null;8 l4 O+ P5 b \/ e& r
}
! ~3 j- K, Q4 ? return sel;1 F( g9 a& ?/ t2 y1 Y" \
}) ^3 F6 ]' c/ u" A; `: Y
5 c2 j% n$ l, A0 I" X
public static Selector getSelector(Object obj, String method) {& ?4 {- s( m9 \$ @& u2 M
Selector sel; A, E3 w* @$ ]( i* G' N
try {; b: P; O* \$ p
sel = new Selector(obj.getClass(), method, false);5 S7 V- m- L+ L1 p( I1 B
} catch (Exception e) {
- ~$ d, L/ h9 b8 A System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 Z' B( g1 q$ { + (obj.getClass()).getName() + ".");) z' f' g9 l2 u
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. l2 z9 X% f. B) y, b, Q: s
System.err.println("The process will be terminated.");
- Y1 u% q4 _# h' _ System.exit(1);& P, E* |% H. \' }, V* i4 e
return null;
) I% g- \$ @7 O% @. ]7 o) X }
! {* Z% k) A8 `' f return sel;% ~8 k% F- |5 W2 e2 z
}
6 ^% r9 w# o2 _} |