org.mentaqueue
Interface Queue<E>

Type Parameters:
E -
All Known Implementing Classes:
AtomicQueue, BlockingArrayQueue, BlockingLinkedQueue, BlockingQueue, BrokenFastQueue, ConcurrentLinkedQueue, LockedQueue, NonBatchingQueue, PooledBlockingArrayQueue, PooledBlockingLinkedQueue, PooledBlockingQueue, PooledConcurrentLinkedQueue, SynchronizedQueue, VolatileQueue

public interface Queue<E>

A queue API that allows batching and pooling of objects. So to offer you first get a mutable object from the queue by calling nextToOffer(), alter the object and call offer(). That allows the queue objects to be pooled, avoiding any garbage collection. And to poll you first call available() to know how many objects you can safely poll, call poll() in a loop and when done call done(). That allows polling to be batched, so you pay a synchronization price only when you call available() and NOT when you call poll().

Author:
Sergio Oliveira Jr.

Method Summary
 long available()
          Return the number of objects that can be safely polled from this queue.
 void done()
          Called to indicate that all polling have been done.
 E nextToOffer()
          Return the next pooled mutable object that can be used by the producer.
 void offer(E e)
          Offer an object to the queue.
 E poll()
          Poll a object from the queue.
 

Method Detail

nextToOffer

E nextToOffer()
Return the next pooled mutable object that can be used by the producer.

Returns:
the next mutable object that can be used by the producer.

offer

void offer(E e)
Offer an object to the queue. The object must have been previously obtained by calling nextToOffer().

Parameters:
e - the object to be offered to the queue.

available

long available()
Return the number of objects that can be safely polled from this queue. It can return zero.

Returns:
number of objects that can be polled.

poll

E poll()
Poll a object from the queue. You can only call this method after calling available() so you know what is the maximum times you can call it. NOTE: You should NOT keep your own reference for this mutable object. Read what you need to get from it and release its reference.

Returns:
an object from the queue.

done

void done()
Called to indicate that all polling have been done.



Copyright © 2012. All Rights Reserved.