Hi,
I'd like to pitch a minor issue which should be addressed while
discussing the future of MINA.
A few weeks ago I started to work on the DS DHCP server. Work has
progressed so far that clients can successfully register IP addresses
with the server and all, although the code is still unfit for general
consumption.
Ir order to implement the DHCP functionality, however, it was necessary
to apply a minor patch to the MINA code base. The patch is necessitated
by the fact that packets which are received via broadcast from a DHCP
client don't have a proper source address. As a consequence, the reply
messages must also be broadcast (or, in some cases sent by unicast to a
different address). The existing code created a new MINA IoSession per
message in order to handle this case, causing quite a lot of overhead
and, worse, a new thread which lingered even after it was done.
In order to do away with the overhead, I introduced a special session
attribute which allows me to re-direct a message while it is sent like this:
InetSocketAddress isa = determineMessageDestination(
request, reply );
session.setAttribute( "destination", isa );
session.write( reply );
This property is used in
DatagramAcceptorDelegate.flush(DatagramSessionImpl) to override the
message destination address like this:
...
if ( !key.isValid() )
{
continue;
}
// HACK: allow destination to be overridden using session
attribute.
SocketAddress destination = session.getRemoteAddress();
Object d = session.getAttribute( "destination" );
if ( null != d && d instanceof SocketAddress )
destination = ( SocketAddress ) d;
int writtenBytes = ch.send( buf.buf(), destination );
...
I am not too happy with this hack, but it was easy and worked. I you
could come up with a more general and elegant solution, I'd be more than
happy.
Joerg Henne