Babak Farhang wrote:
Ack. That wasn't clear.

Suppose we plan to expose a web service through MINA, and the typical
dynamically generated response is about 100K.  The response is to be
served in non-blocking mode. I'm asking whether there's a way for me
to chunk the output incrementally, say 10 times, 10K each time, rather
than all the 100K in one go.  (The objective being to reduce the
runtime memory footprint in order to scale to more clients.)

Is this possible?
Sure. Otherwise the full MINA project would be just a waste :)

In your handler, just write data in small chunks until all has been written. Something like :

for ( int i = 0; i < yourData.lengh; i+=10000 ) {
   byte[] temp = new byte[100000];
   System.arrayCopy( yourData, i, temp, 0, 10000);
   session.write( temp );
}

PS: I just write this code from the top of my head, I don't remember exactly what is the arrayCopy parameter order. Plus I didn't handled the limits correctly (ie, your data buffer might not stop on a 10000 border ;). I also assumed that your data is stored in a byte[], if it's a String, just spilt it using substring().

If you are using a protocol encoder, that's a different story. But I guess this is not the case... Otherwise, you will have to manage the chunking there too.

--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org


Reply via email to