mina-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lécharny <elecha...@gmail.com>
Subject Re: Reliable delivery
Date Mon, 08 Jul 2013 09:27:58 GMT
Le 7/8/13 10:44 AM, sbrytskyy a écrit :
> My question is how to get if possible message in method 
> *public void exceptionCaught(IoSession session, Throwable cause)*
>
> Let's do step by step using standard mina example chat.
> 1. Server and client are deployed on different computers
> 2. Start server
> 3. Start client
> 4. Login to server
> 5. Send test message
>
> So far everything goes well.
>
> 6. Unplug network cable on server
> 7. Meanwhile send message from the client
>
> Result:
> Message will not be passed to server. Exception will be thrown and method
> *exceptionCaught* will be executed.
>
> Is it possible to know from *IoSession* what message was lost?

I'm afraid that i's not really easy.
You can try to get the message currently being processed with
session.getCurrentWriteMessage(), as it is likely you had an issue with
the message being processed.

Otherwise, if you kep the writeFuture in the session, you can get the
exception associated with it when you get an exceptionCaught. Sadly, you
don't have the opposite relation (ie, the exception caught does not gie
you any information about which message was being processed).


> Or is there any other correct way of error handling and reliable message
> delivery?

In general, yes, there is a correct way to process messages : *always*
process the messageSent event before sending a new message. You will
have to manage a state in your session for that, which means you have to
add a attribute in your session to store the current status of each message.

Of course, that would make it more complex, and that would also mean
that you will serialize the writes in a session, and in some cases, it's
not a good idea. But basically, the following algorithm could work
pretty well :

messageReceived :
 - prepare the response
 - store a state MESSAGE_SENT <- message in the session
 - write the message

messageSent :
  - store a state READY in the session (it replaces the MESSAGE_SENT state)

exceptionCaught :
 - get the state from the session,  and extract the message from it

Hope it helps...


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Mime
View raw message