Search code examples
javafifoapache-commons-collection

FifoBuffer - apache common collections 4 replacements


I want to upgrade to apache.commons.collections4, but some classes as CircularFifoBuffer and UnboundedFifoBuffer are dropped

import org.apache.commons.collections.buffer.CircularFifoBuffer;

What are the right replacements for such classes?

Found several suggestions:

hadJan Haderka

Or perhaps there's yet another option:

replace buffer with MinMaxPriorityQueue which on it's own is also not thread safe, but guava fortunately provides wrapper for thread safety in form of Queues.synchronizedQueue(Queue q) call. Since we use guava elsewhere already it should be ok to use the library instead of commons. Not sure about performance comparison of the two tho.

Cedric Reichenbach

it seems like Queues#synchronizedQueue is indeed the equivalent of BufferUtils#synchronizedBuffer, i.e. synchronizes every access to the contained queue/buffer. However, a more precise match in Guava for CircularFifoBuffer would probably be EvictingQueue, or, since the sync wrapper works for any Queue, even Java's own Apache's new CircularFifoQueue.

I didn't find answer in mailing list or release notes


Solution

  • Found answers in task COLLECTIONS-432 Replace Buffer interface with java.util.Queue

    BoundedFifoBuffer is replaced with java.util.concurrent.ArrayBlockingQueue

    CircularFifoBuffer is replaced with java.util.concurrent.ArrayBlockingQueue.

    PredicatedBuffer transfered into PredivatedBuffer

    PriorityBuffer is replaced with java.util.PriorityQueue

    SynchronizedBuffer is replaced with java.util.concurrent.SynchronizedQueue

    BlockingBuffer is replaced with java.util.concurrent.BlockingQueue (practical java.util.concurrent.ArrayBlockingQueue or java.util.concurrent.SynchronizedQueue)

    BoundedBuffer is replaced with java.util.concurrent.ArrayBlockingQueue

    TransformedBuffer transfered into TransformedQueue

    UnboundedFifoBuffer is replaced with java.util.concurrent.ArrayBlockingQueue