import swarm.Selector; |" L4 K! J1 c. \9 |: T; F0 M
# J. F/ b3 w' w W# u5 Hpublic class SwarmUtils {
/ t o. Z$ y$ L public static Selector getSelector(String name, String method) {. @- C* V$ u7 ]
Selector sel;
- l! I9 `2 [: f, s& }. a+ f) p try {
$ {$ ?4 v9 N7 k- i7 U4 j9 r1 o: v sel = new Selector(Class.forName(name), method, false);
: G* n3 f2 |$ v' `$ J; q } catch (Exception e) { T; a* U8 U3 H. t) t
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: t. `* p" I0 k: y+ I; _ System.err.println(name + "." + method + " returns " + e.getMessage());% X4 J0 P3 l" n$ A; u% l% S
System.err.println("The process will be terminated.");9 p9 i2 W" U1 V: V
System.exit(1);4 d, o4 n. I/ B# \. R" w
return null;3 F8 x$ G1 j p/ E3 q" M( i
}
' ^( i& m* |6 o$ Z/ `1 D return sel;
! O2 V' y+ O8 h, ~) a b+ J0 Q1 o2 N }3 V F! L& A- k; d4 S
, G6 }8 J. Z, N* ^2 \! z( C
public static Selector getSelector(Object obj, String method) {
! _ ~- s- G( ^ Selector sel;
+ y' R; Q; w+ N. Q4 f7 M try {' j5 E0 N, d, K6 h( H$ [& b& `7 M
sel = new Selector(obj.getClass(), method, false);
% X& K5 n# ?# I! h' u( U3 p } catch (Exception e) {5 t- P9 U1 Z% J2 p
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", ~* w8 |; ]/ N6 ~* W
+ (obj.getClass()).getName() + ".");0 d! Q% s- S3 V
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 c; v/ S! F3 s
System.err.println("The process will be terminated.");# _7 r8 J7 R% t: n3 c+ ?
System.exit(1);
& @6 N6 F3 ^4 @# \) I return null;
8 ]8 U! T) b2 X }8 r0 p: w2 B9 [% E2 w0 o
return sel;
@8 R6 @& I, |: i& F0 e3 r9 o }
0 U& C0 e" Z( m} |