org.mentaqueue
Class LockedQueue<E>

java.lang.Object
  extended by org.mentaqueue.LockedQueue<E>
All Implemented Interfaces:
BatchingQueue<E>

public class LockedQueue<E>
extends Object
implements BatchingQueue<E>


Constructor Summary
LockedQueue(Builder<E> builder)
           
LockedQueue(Class<E> klass)
           
LockedQueue(int capacity, Builder<E> builder)
           
LockedQueue(int capacity, Class<E> klass)
           
 
Method Summary
 long availableToPoll()
          Return the number of objects that can be safely polled from this queue.
 void donePolling()
          Called to indicate that all polling have been concluded.
 void donePolling(boolean lazySet)
          Called to indicate that all polling have been concluded.
 void flush()
          Dispatch *immediately* all previously obtained objects through the nextToDispatch() method to the queue.
 void flush(boolean lazySet)
          Dispatch all previously obtained objects through the nextToDispatch() method to the queue.
 E nextToDispatch()
          Return the next pooled mutable object that can be used by the producer to dispatch data to the queue.
 E poll()
          Poll a object from the queue.
 void rollback()
          Pretend you never polled the last object you polled since the last time you called donePolling().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockedQueue

public LockedQueue(int capacity,
                   Builder<E> builder)

LockedQueue

public LockedQueue(Builder<E> builder)

LockedQueue

public LockedQueue(Class<E> klass)

LockedQueue

public LockedQueue(int capacity,
                   Class<E> klass)
Method Detail

nextToDispatch

public E nextToDispatch()
Description copied from interface: BatchingQueue
Return the next pooled mutable object that can be used by the producer to dispatch data to the queue.

Specified by:
nextToDispatch in interface BatchingQueue<E>
Returns:
the next mutable object that can be used by the producer.

flush

public void flush(boolean lazySet)
Description copied from interface: BatchingQueue
Dispatch all previously obtained objects through the nextToDispatch() method to the queue.

Specified by:
flush in interface BatchingQueue<E>
Parameters:
lazySet - flush (i.e. notify the consumer) in a lazy way or flush immediately

availableToPoll

public long availableToPoll()
Description copied from interface: BatchingQueue
Return the number of objects that can be safely polled from this queue. It can return zero.

Specified by:
availableToPoll in interface BatchingQueue<E>
Returns:
number of objects that can be polled.

flush

public final void flush()
Description copied from interface: BatchingQueue
Dispatch *immediately* all previously obtained objects through the nextToDispatch() method to the queue.

Specified by:
flush in interface BatchingQueue<E>

poll

public E poll()
Description copied from interface: BatchingQueue
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.

Specified by:
poll in interface BatchingQueue<E>
Returns:
an object from the queue.

donePolling

public void donePolling(boolean lazySet)
Description copied from interface: BatchingQueue
Called to indicate that all polling have been concluded.

Specified by:
donePolling in interface BatchingQueue<E>
Parameters:
lazySet - notify the producer in a lazy way or notify the producer immediately

donePolling

public final void donePolling()
Description copied from interface: BatchingQueue
Called to indicate that all polling have been concluded.

Specified by:
donePolling in interface BatchingQueue<E>

rollback

public final void rollback()
Description copied from interface: BatchingQueue
Pretend you never polled the last object you polled since the last time you called donePolling(). You can call this as many times as you want before you call donePolling() and rollback any poll() you have done. This is unaffected by availableToPoll(). Only donePolling() reset the counter of the last polled objects. Because rollback() reset the counter of the last polled objects, you can even call it twice in a row and the second rollbac() will have no effect since you have polled anything.

Specified by:
rollback in interface BatchingQueue<E>


Copyright © 2012. All Rights Reserved.