On 12/15/10 11:51 PM, Mark Harris wrote:
I've not done anything like this before in any programming task and
am a bit lost when it comes to picturing what I need to do in terms
of new functionality. The message to the server is written to the
IOSession (set when the server connection is established), which
then waits until a response is received before that response is
processed. I'm guessing that it is here somewhere that I would need
to add appropriate functionality.
Yep. Mainly detect either a disconnection (and an Closed() event will
be fired), or use a timeout for the expected response, and if the
response has not been received, then retry, after having closed the
session and reconnected.
Many thanks for this, and for the example you included.
The issue that I'm finding is that when I pull the network cable from
the box I'm using, errors are being caught in the exceptionCaught()
method of my IoHandlerAdapter implementation. This is fine for
tidying up after oneself (e.g. closing the session), but I'm not sure
how to propagate the exception from there back up to where the client
is waiting for a response after writing the request to the session.
I've tried to throw an InterruptedException from exceptionCaught()
but it gets lost within the auspices of the thread somewhere.
In the example given in svn.apache.org, the exceptionCaught() method
doesn't seem to explicitly propagate any exception either, so I'm
wondering whether I'm approaching the solution in the wrong way.
What we do when we send a request, as each request has a unique id (the
MessageId in our case) is that we are able to match the future a client
is waiting on as we have associated this future with the messageId in a
Map. If we get an exceptionCaugth(), we get the messageId for the
message that generated this exception, and find the associated future,
that we now cancel.
If the exception is not associated with any messageId, then you should
close the session, and reconnect it, because it's very likely that the
exception is due to some big problem.
In any case, once the future has been cancelled, the waiting thread will
be waken up, and you'll be able to proceed with a retry.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com