import swarm.Selector;
& |( [1 D9 P4 t! r) M. s
. c6 r( G+ y Qpublic class SwarmUtils { E" k7 [1 w W3 A
public static Selector getSelector(String name, String method) {
: Y: q% l Y9 S Selector sel;
! i( A6 K7 V& D/ Z8 v3 `/ H try {) T1 ]! @ ~, u$ C6 x* x) G
sel = new Selector(Class.forName(name), method, false);% Z; B4 T9 f! y+ U" W$ |) a/ V
} catch (Exception e) {2 J; y' j2 P( y# N/ j
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% ?. X2 x% {1 a+ b System.err.println(name + "." + method + " returns " + e.getMessage());' ^) ]5 w. b5 U; l1 c4 E9 b
System.err.println("The process will be terminated.");& P' F' }4 X4 U0 S2 ?' L
System.exit(1);
: J6 U# z* _8 P& t return null;. _; d* z# e) x: |
}1 k0 t `0 {. I v+ h+ D
return sel;
, }- X) u" Y/ r( N! |6 S, h }
# `2 f m+ T8 z( w8 Z6 \
1 ?5 h h, i3 h# H! K7 H public static Selector getSelector(Object obj, String method) {8 @; d! D5 B) h P9 ^- G+ A
Selector sel;
, U Y# H& P0 M try {- m. l- b& m' Y* `- E# T1 s
sel = new Selector(obj.getClass(), method, false);
( K v G% P$ P* i: x } catch (Exception e) {% K. H: E2 P: S/ I
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 v/ W y' O9 I2 E + (obj.getClass()).getName() + ".");# I) i5 D Z `
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); `3 V0 q; ^" H h, y
System.err.println("The process will be terminated.");8 B$ ~9 a+ U: [' |
System.exit(1);6 J( z) X% G- r- o6 y
return null;
* j4 m( u( o- |$ y; Y9 | }0 Q0 _ O& }7 C6 N2 O" `2 Y0 B
return sel;
2 Q0 _0 e- h7 V3 S; _) W0 f }
* w/ X0 P$ N5 ^5 R} |