com.appenginefan.toolkit.common
Class PersistentQueue<T>

java.lang.Object
  extended by com.appenginefan.toolkit.common.PersistentQueue<T>

public class PersistentQueue<T>
extends Object

An experimental!! class that can be used to persist objects in the data store in an ordered fashion. This class does not implement the java.util.Queue interface, since certain aspects (like size) are inefficient to implement. However, it tries to use the same method names and semantics as the core Queue interface, thus making it an easy class to use. If you run into any problems, please let me know!


Constructor Summary
PersistentQueue(Counter idGenerator, Persistence<T> store, String name)
          Constructor
 
Method Summary
static
<T> PersistentQueue<T>
createQueue(String name, Persistence<T> persistence)
          Creates a persistent queue, using the given backend and a given name
 boolean offer(T element)
          Inserts the specified element into this queue, if possible.
 T peek()
          Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.
 T poll()
          Retrieves and removes the head of this queue, or null if this queue is empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistentQueue

public PersistentQueue(Counter idGenerator,
                       Persistence<T> store,
                       String name)
Constructor

Parameters:
idGenerator - a counter (must be idgenerator-capable) that is used to maintain an order in the queue
store - a place to persist queue elements
name - a key that is used to persist the elements in the datastore. Must not contain any slashes.
Method Detail

createQueue

public static <T> PersistentQueue<T> createQueue(String name,
                                                 Persistence<T> persistence)
Creates a persistent queue, using the given backend and a given name

Parameters:
name - the name to be used for persisting elements (must not contain slashes)
Returns:
a queue object

offer

public boolean offer(T element)
Inserts the specified element into this queue, if possible.

Parameters:
element - the element to insert. null is not allowed.
Returns:
true if it was possible to add the element to this queue, else false
Throws:
NullPointerException - if the element was null

poll

public T poll()
Retrieves and removes the head of this queue, or null if this queue is empty.

Returns:
the head of this queue, or null if this queue is empty.

peek

public T peek()
Retrieves, but does not remove, the head of this queue, returning null if this queue is empty. Returns: the head of this queue, or null if this queue is empty.