mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niklas Therning (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DIRMINA-263) Partially read messages
Date Thu, 14 Sep 2006 09:14:23 GMT
    [ http://issues.apache.org/jira/browse/DIRMINA-263?page=comments#action_12434619 ] 
Niklas Therning commented on DIRMINA-263:

In messageReceived() the passed in ByteBuffer will contain zero or more complete requests
followed by a single complete or partial request. MINA has no idea of what a request looks
like in your particular protocol. Whether requests from your client get concatenated or split
up on the server side depends on the network connecting the client and server and how the
network stacks are setup on both sides. If you don't consume the whole ByteBuffer in messageReceived()
the rest will be thrown away. The only thing MINA ensures is that received ByteBuffers are
delivered to your IoHandler in order.

To tell MINA to do what you want, i.e. messageReceived() should only be called for complete
messages and one message should be delivered at a time, the easiest solution is to implement
a ProtocolDecoder. Have a look at the CumulativeProtocolDecoder. I think it will help you
do exactly what you want. In your case you could have yuor ProtocolDecoder return ByteBuffer
instances but you could also have it return a custom request message object which you need
to define yourself. In that case you won't have to deal with ByteBuffers at all in your IoHandler.

The latest version of CumulativeProtocolDecoder in SVN has a nice example in the Javadoc.
I think you might want to have a look at it. If you don't want to check out the latest code
from SVN have a look at DIRMINA-199.

> Partially read messages
> -----------------------
>                 Key: DIRMINA-263
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-263
>             Project: Directory MINA
>          Issue Type: Wish
>    Affects Versions: 0.9.5
>         Environment: win xp
>            Reporter: Hooman Valibeigi
> assume we have a client that sends its requests consecutively ()
> I tested it using MINA and I found that MINA only notifies the server side IoHandler
one time for a sequence of requests
> I mean when the client sends 3 consecutive requests the server's messageReceived method
will be invoked only once
> (a Request in my opinion is a package containing a request ID and data related to the
> so my question is how should we handle the ByteBuffer that contains more than one requests
> the other IoSessions should not wait while the server is processing the interminable
requests of a client
> in other word the server becomes busy while processing all sent and incoming requests
of one client and may never finish
> even If it responds to the first buffered request in ByteBuffer and leave the remaining
requests in hope that they will remain intact for the next messageReceived invocation from
the same IoSession, it is wrong, since any remaining byte in ByteBuffer will be released after
the messageReceived method is finished, whether we read them or not
> so we should read all the incoming bytes or we will lose them
> I ask you what is the correct solution to handle these kind of requests ?
> in short, I want to process one request per messageReceived invocation and I expect that
IoHandler will notify me again if I have unread data from previous messageReceived calls
> this question may be translated in other way as below
> when is messageReceived invoked ?
> - when the selecetor selects a socket which is readable ?
> - so what happens if I dont process all the available data (all requests) within the
ByteBuffer in one shot ?
> - also another question arise. is there any chance that the ByteBuffer parameter from
messageReceived, does not have the full request data ? I mean is it possible that a request
arives in several messageReceived calls ? I ask this because a ByteBuffer has a limit so It
brings in mind that we may encounter several problems
> such that
> - a ByteBuffer containing one partial request
> - a ByteBuffer containing more than one request (all complete)
> - a ByteBuffer containing more than one request (but the last one is partial)

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message