qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rafael Schloming <rafa...@redhat.com>
Subject Re: Use of AMQShortString in client side code
Date Thu, 20 Sep 2007 11:40:21 GMT
Rupert Smith wrote:
> Rafael,
> 
> Is there much difference between your decoder that works on multiple byte
> buffers, and a decoder that works on a byte buffer but that could be passed
> a special aggregating byte buffer that pulls together several byte buffers
> and presents them as if they are one buffer? That is, do you think the
> latter option could be just as efficient as the former one?
> 
> The aggregating byte buffer concept sounds like a very useful re-usable
> building block, and conceptually neater than a special decoder that works on
> many buffers; it can simply be substituted in wherever a ByteBuffer can be
> used. I'd like to pull it out of the code, and write a few tests to exercise
> it, as an experiment.
> 
> Writing out the message, from an aggregated list of byte buffers, sounds
> like it can be done efficiently as a gathering write.

An aggregating byte buffer sounds nice, but I don't think it would work 
so well in practice. Despite not being final, the ByteBuffer class isn't 
actually designed to be extended. It contains the internal 
representation for heap buffers, and it is package visible to the other 
nio classes which directly access it. Since an aggregating ByteBuffer 
wouldn't use that, it could break in strange ways when interacting with 
other classes.

Also, performance-wise an aggregating ByteBuffer probably wouldn't do so 
well since you'd have to return false/null from hasArray()/array(), and 
so you'd nullify the benefit from bulk get/put operations.

And finally it would be a lot of work since you'd need to also create 
specialized implementations of all the view classes (e.g. 
asCharBuffer(), asShortBuffer(), etc), and that still wouldn't guarantee 
that your impl would work correctly with the rest of the nio package.

With my own FragmentDecoder it's a fairly simple piece of code, and it's 
easy for me to continue to use bulk get/put operations. The class is 
org.apache.qpidity.codec.FragmentDecoder (in common) if you want to have 
a look.

--Rafael


Mime
View raw message