import swarm.Selector;) h. L# r1 o2 W6 q# ]) c
7 c7 q* J/ Q$ [- G5 L- `
public class SwarmUtils {/ s0 S) J& T* q
public static Selector getSelector(String name, String method) {
0 Q# N; q! z( o0 \) R Selector sel;, w2 ~: m/ E( V6 k- Z, V( [" r
try {
8 n3 L: H. f5 Q# T# q+ S sel = new Selector(Class.forName(name), method, false);
' I5 T1 m) X, y+ j+ Z7 ^ } catch (Exception e) {
8 j' D9 T9 A! I System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");$ t: A. x i+ S1 F4 h9 f+ o% T
System.err.println(name + "." + method + " returns " + e.getMessage());
0 A( A* c8 _( A n$ a/ f! T System.err.println("The process will be terminated.");
: h* h: n3 }& ^ System.exit(1);
! C: ?" R! r6 l5 A' u1 o return null;3 \8 ?# \1 C+ Z- S
}. T E- [% V: s, S, W
return sel;0 E [/ M# a! E! J, |% d
}
/ N( v# k/ t6 @0 @# {& e: V3 @- P( P: o2 o/ H4 ]$ K4 t: q% J8 Z U
public static Selector getSelector(Object obj, String method) {% f) M2 X. U, p
Selector sel;) Z( C4 {" Q! k3 f4 J% f, c4 Q# l
try {
9 W5 ?; c" L* l1 N sel = new Selector(obj.getClass(), method, false);( D- {$ _7 p/ t6 v$ T7 k$ [
} catch (Exception e) {
! M+ Y, o7 ^# G7 Z3 d3 s System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- b' |+ U4 ?* Y' d# M + (obj.getClass()).getName() + ".");
5 V- W! j* C: k System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, d5 a8 ^" o/ I
System.err.println("The process will be terminated.");
$ r" r+ x, B# p9 l6 D System.exit(1);
; o d" o3 o0 Y* `: z return null;2 n7 A+ e- L/ o- A9 Y$ j# V# G H, e
}
) n! G z, J" F: W p return sel;1 g- K2 w5 d& _5 }0 a, v& Q. s" @
}9 F4 V6 E H2 w1 @' R
} |