Le 3/26/14 5:58 PM, Archer, Garry a écrit : > Hello All, > > I have a Mina-using application that sends data as a number of messages to a > device that acknowledges receipt of each message. When the last message has > been sent, the device recognises yhat it is the last message and then the > session is closed. > > The problem I have is that the session is closed after my application has > sent only the first message and the device never receives it. > > The sending application, which extends IoHandlerAdapter, calls 'messageSent' > and then 'messageSent' in IoFilterAdapter is subsequently called... and so > on...
The messageSent event is generated by the server, when it has sent a full message. The client has nothing to do with the generation of this event, actually it might even not have received the message at all... This event is just emitted when all the bytes have been pushed into the socket. > > Without showing the entire debugging scenario there is a 'WriteRequestQueue' > in 'DefaultIoFilterChain' that when it empties then the session is closed. > > It seems the queue is emptied after my application has only sent one message > even if there are still other messages being sent. > > 'WriteRequest's are passed on by the 'fireMessageSent' method in > 'DefaultIoFilterChain' which has two inner classes, 'HeadFiler' and > 'TailFilter,' that process the 'WriteRequestQueue' > > If the 'WriteRequestQueue' is empty (and herein the problem lies...) then the > session calls a "polling I/O processor" which attempts to write the message, > but this throws an I/O exception and then the session closes. The IO Exception will actually close the session. The key here is to find why an exception is being thrown. The way it should work is the following : - the server receives a messageReceive event - it creates the first message to be sent back to the client - the message is written into the IoSession ... and the server now waits for the first message sent event. - a messageSent event is received by the server - if it has some more message to send, just do that, and wait ... - a messageSent event is received by the server - if it has some more message to send, just do that, and wait ... (and so on, until there is no message to write to the client) The messageSent part will obviously have to get the list of message to be sent into the IoSession instance, and you should never close the session. -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
