> for ( int i = 0; i < yourData.lengh; i+=10000 ) {
> byte[] temp = new byte[100000];
> System.arrayCopy( yourData, i, temp, 0, 10000);
> session.write( temp );
> }
If session.write(temp) doesn't block, then we might end up having
written all 100K into memory before anything was written to the
socket. No?
I was thinking maybe there's a way to write a 10K chunk, and have MINA
callback me back when it's finished writing it, so that I can write
the next 10K chunk, and so on, until the whole message is written.
-Babak
On Wed, Mar 25, 2009 at 2:44 AM, Emmanuel Lecharny <[email protected]> wrote:
> 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
>
>
>