import swarm.Selector;
! a2 D% l- W: Y; m3 @/ N/ \9 ^
% y: X2 l' ~# o: l' p0 wpublic class SwarmUtils {
0 b% J% ?/ I2 D8 j3 a' {2 R public static Selector getSelector(String name, String method) {5 {6 ?& O% T- v% e: \) P$ h
Selector sel;7 ] L# c3 G- `) E6 l$ e
try {" Q5 S$ ~$ X' d0 U. |
sel = new Selector(Class.forName(name), method, false);
" ] ^( d# c3 w. Z( |, d } catch (Exception e) {, ]8 ~* A, i4 [: W8 ]- [
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
6 W( W5 V# s1 g1 s2 W& F% w2 p System.err.println(name + "." + method + " returns " + e.getMessage());) u0 Z) L8 R2 ]+ |
System.err.println("The process will be terminated.");
! n1 F9 ~+ R' e7 Y- m/ | System.exit(1);
7 S( O! N- `* W9 u return null;
3 O3 [+ p# S' S. W }
7 [, g7 q* x- `; ? return sel;% f F4 u+ P2 u9 m
}
+ i ^/ h* T; w. T. d, I+ U5 f9 h2 w) r1 X5 Y' T" h
public static Selector getSelector(Object obj, String method) {
% n3 v* K4 v! `0 k: l Selector sel;1 ]2 I$ @4 k+ J" ^" e+ a) y
try {0 X+ r# x9 T$ P% H
sel = new Selector(obj.getClass(), method, false);5 j- J* n0 r0 P1 r( i; K2 _+ a# q
} catch (Exception e) {$ q- u, {# o2 M* c! l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "9 i# G% j+ n f/ ?7 X4 N# q
+ (obj.getClass()).getName() + ".");
[6 |- R& z& O: s System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 y& \! S1 ^6 p; \% Z
System.err.println("The process will be terminated.");. {) A# C7 {( h' E5 _
System.exit(1);1 o3 C3 f6 c G9 y8 ]& H
return null;
" b' S6 G; i& n+ o3 P" n7 a" D5 O }
4 Z. U0 a' r0 Y- ~ return sel;! m# m v! ]* {. ?/ ^2 s: O% H
}# B; g7 T0 M$ L, ]* n
} |