import swarm.Selector;8 N$ w8 {. r. i3 o6 k
. x& o$ \+ U* X7 o
public class SwarmUtils {8 P/ ]& W* O3 c
public static Selector getSelector(String name, String method) {
% Y( g" ?# E7 @! ?9 ?' x Selector sel;
- R9 u n+ O8 ^: L( T. M% M, S try {" P) ]7 c+ V7 K5 u( P
sel = new Selector(Class.forName(name), method, false);
7 C7 ?2 k( T4 S! g } catch (Exception e) {+ ?7 \& P6 \' o! D9 _# ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");1 h- [3 c3 C: X# F8 N
System.err.println(name + "." + method + " returns " + e.getMessage());
# a5 K- f& N( ]$ S- m E- m System.err.println("The process will be terminated.");
7 h# Y) v' I, N7 @! O; { System.exit(1);
4 l. {+ H3 Y" e l3 k" P return null;
7 [0 X' p. d. R S6 B3 J9 F }
+ k# D; v7 S' S5 R return sel;) l7 D ]+ h) b1 p
}
3 d$ b7 R1 `& B! M) o0 r
% U e( y X( r3 M/ G' j public static Selector getSelector(Object obj, String method) {
5 {" T2 S# w0 B+ v7 T$ ^0 \ Selector sel;3 \( E- k1 c8 L5 }$ G
try {$ D; K4 K( i, ]4 t$ s4 b
sel = new Selector(obj.getClass(), method, false);( i$ t/ L7 \5 J# W+ G" M$ i7 p& M
} catch (Exception e) {! t/ n2 U! ^; {& S7 q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ p7 @( h, w/ k1 d, p + (obj.getClass()).getName() + ".");+ W# k0 F. R% i* h& Z" B, b; D
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 K3 Z, K9 {# g* t, n; j+ ]3 Y9 Z. V System.err.println("The process will be terminated.");% C f B6 e* v( \
System.exit(1);: z$ e& }9 p! \, z0 z' n. N
return null;5 \, d l' j4 E! @3 c8 y
}
: ?% J/ z* g( e- Q# J' E# {2 P/ \, V return sel;
* W/ I, E- s x }3 I. G4 o9 E- ]* e1 r. F5 Z# [9 V
} |