Le 26/08/15 12:14, Nitin a écrit :
> Dear All, 
>  
>       We have developed one server using Apache MINA V2.0.9 where multiple
> vendors connect and send the messages which needs to be processed and then
> response have to be sent back to vendor. Currently we have put a strategy
> that vendor has to send one message per connection and after getting
> response or timeout vendor has to close the connection.
>       
>       We also have persistance connection open from our MINA based server
> with third party server whcih is tcp/ip channel and for each vendor request
> we get we have to send the received message to this third party server. Past
> 3-4 days we have observed that some of the received vendor messages when we
> try to send on the third party server over persistance connection they are
> actually not sent even after calling iosession.write(object message) method.
> This operation is asynchronous; IoHandler.messageSent(IoSession, Object)
> will be invoked when the message is actually sent to remote peer. In our
> observation we found that the messageSent was not called for those missing
> messages.
The messageSent event will be generated when the message has actually
been written fully in the socket. You have no control on this event, you
can only react on such an event in your handler.


>       
>       We have our own ProtocolCodecFactory implemented is used for
> endocing/decoding messages from our server to third party server.
>       
>       In the IoSession Interface documentation it is mentioned that 
>       
>       Thread Safety
>       
> IoSession is thread-safe. But please note that performing more than one
> write(Object) calls at the same time will cause the
> IoFilter.filterWrite(IoFilter.NextFilter,IoSession,WriteRequest) to be
> executed simultaneously, and therefore you have to make sure the IoFilter
> implementations you're using are thread-safe, too. 
>  
>  Does above statement means that I have to make sure my encoder should be
> thread-safe. 

Yes.
>  
> Below is my Protocol Encoder class
>  
> public class DefaultMyMsgEncoder extends ProtocolEncoderAdapter
> {
>     public DefaultMyMsgEncoder()
>     {
>     }
>  
>     public void encode(IoSession session, Object msg, ProtocolEncoderOutput
> out) throws Exception
>     {
>         
>             MyMsg myMsg = (MyMsg) msg;
>             IoBuffer buffer =
> IoBuffer.allocate(myMsg.getLengthBytes().length+myMsg.getMsgBytes().length
> );
>          buffer.put(myMsg.getLengthBytes());
>          buffer.put(myMsg.getMsgBytes());
>          buffer.flip();
>          out.write(buffer);
>         
>     }
> }

It's possible that one message override another one before it's written
into the buffer. Try to add a lock associated with the session, and
protect the section here you create the buffer.



Reply via email to