Buffering ChannelBuffers

Frederic Bregier fredbregier at free.fr
Sat May 23 01:56:23 EDT 2009


Hi David,

I don't get your problem. If you receive your data by chunk into
ChannelBuffer,
why you cannot directly write to your InputStream directly chunk by chunk?

For instance:
from your handler like a SimpleChannelUpstreamHandler or
SimpleChannelHandler:
- when the connection is connected (channelConnected(...) method),
initialize your InputStream (or from any special message received)
- when you receive the chunk in messageReceived(...) method, simply writes
this chunk to the InputStream
- when the connection is closed (channelClosed(...) method or the send is
over by a special message received), then close your InputStream

Does this answer your question?

One thing too, doing this is synchronous on InputStream (not Nio), so
probably you will have to insert a OrderedMemoryAwareThreadPoolExecutor
before your handler in order to prevent to block IO threads in such blocking
actions.

HTH,
Frederic


David Hoyt wrote:
> 
> If there's a way I can continuously add to the InputStream as chunks come
> in, then I could process my InputStream asynchronously too.
> 
> I did consider, btw, just using a list and adding each channelbuffer to
> that
> - but I was hoping there would be a better or more efficient way or
> something else inside the API that already does it.
> 
>  
> 
> From: netty-users-bounces at lists.jboss.org
> [mailto:netty-users-bounces at lists.jboss.org] On Behalf Of David Hoyt
> Sent: Friday, May 22, 2009 11:21 AM
> To: netty-users at lists.jboss.org
> Subject: Buffering ChannelBuffers
> 
>  
> 
> Hello,
> 
> So here's my problem - I need to buffer all my incoming data in memory
> until
> the connection is closed and then create a java.io.InputStream that
> represents all that data that I can then pass on. How do you suggest doing
> that?
> 
> I looked at using a CompositeChannelBuffer, but I can't continually add
> ChannelBuffers as they come in. With CompositeChannelBuffer (and
> ChannelBuffers.wrappedBuffer(.)), you have to have all the ChannelBuffers
> up
> front (there is no "addChannelBuffer() method on CompositeChannelBuffer).
> Once I have all the data, I see that I can create a
> ChannelBufferInputStream.
> 
>  
> 
> So my code should proceed as follows:
> 
> 1. Connection is made with server
> 
> 2. File is downloaded asynchronously
> 
>     a. As the file is downloaded in chunks, put each chunk (ChannelBuffer)
> into a CompositeChannelBuffer or some other container
> 
> 3. When file is done or the connection closes, create an InputStream from
> the buffered data
> 
> 4. Process the InputStream normally
> 
>  
> 
> My main problem is figuring out 2a. I could use some help since I'm still
> learning the netty API.
> 
> Thanks!
> 
> 
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
> 
> 


-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/Buffering-ChannelBuffers-tp2958986p2961046.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list