More information: http://www.cs.berkeley.edu/~mdw/proj/seda/

seda.sandStorm.core
Class FiniteQueue

java.lang.Object
  |
  +--seda.sandStorm.core.FiniteQueue
All Implemented Interfaces:
ProfilableIF, QueueIF, SinkIF, SourceIF

public class FiniteQueue
extends java.lang.Object
implements QueueIF, ProfilableIF

The FiniteQueue class is a simple implementation of the QueueIF interface, using a linked list.

Author:
Matt Welsh
See Also:
QueueIF

Constructor Summary
FiniteQueue()
          Create a FiniteQueue with no enqueue predicate.
FiniteQueue(EnqueuePredicateIF pred)
          Create a FiniteQueue with the given enqueue predicate.
FiniteQueue(java.lang.String name)
          Create a FiniteQueue with no enqueue and the given name.
 
Method Summary
 QueueElementIF[] blocking_dequeue_all(int timeout_millis)
          This method blocks on the queue up until a timeout occurs or until an element appears on the queue.
 QueueElementIF blocking_dequeue(int timeout_millis)
          Just like blocking_dequeue_all, but returns only a single element.
 QueueElementIF[] blocking_dequeue(int timeout_millis, int num)
          This method blocks on the queue up until a timeout occurs or until an element appears on the queue.
 QueueElementIF[] blocking_dequeue(int timeout_millis, int num, boolean mustReturnNum)
           
 QueueElementIF[] dequeue_all()
          Dequeues all available elements, or returns null if there is nothing left on the queue.
 QueueElementIF dequeue()
          Dequeues the next element, or returns null if there is nothing left on the queue.
 QueueElementIF[] dequeue(int num)
          Dequeues at most num available elements, or returns null if there is nothing left on the queue.
 QueueElementIF[] dequeue(int num, boolean mustReturnNum)
           
 void enqueue_abort(java.lang.Object key)
          Abort a provisional enqueue.
 void enqueue_commit(java.lang.Object key)
          Commit a provisional enqueue.
 boolean enqueue_lossy(QueueElementIF enqueueMe)
          Enqueues the given element onto the queue.
 void enqueue_many(QueueElementIF[] enqueueMe)
          Given an array of elements, atomically enqueues all of the elements in the array.
 java.lang.Object enqueue_prepare(QueueElementIF[] enqueueMe)
          Provisionally enqueue the given elements.
 void enqueue(QueueElementIF enqueueMe)
          Enqueues the given element onto the queue.
 EnqueuePredicateIF getEnqueuePredicate()
          Return the enqueue predicate for this sink.
 int profileSize()
          Return the profile size of the queue.
 void setEnqueuePredicate(EnqueuePredicateIF pred)
          Set the enqueue predicate for this sink.
 int size()
          Return the size of the queue.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FiniteQueue

public FiniteQueue(EnqueuePredicateIF pred)
Create a FiniteQueue with the given enqueue predicate.

FiniteQueue

public FiniteQueue()
Create a FiniteQueue with no enqueue predicate.

FiniteQueue

public FiniteQueue(java.lang.String name)
Create a FiniteQueue with no enqueue and the given name. Used for debugging.
Method Detail

size

public int size()
Return the size of the queue.
Specified by:
size in interface SourceIF

enqueue

public void enqueue(QueueElementIF enqueueMe)
             throws SinkFullException
Description copied from interface: SinkIF
Enqueues the given element onto the queue.
Specified by:
enqueue in interface SinkIF
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
element - The QueueElementIF to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.
SinkClosedException - Indicates that the sink is no longer being serviced.

enqueue_lossy

public boolean enqueue_lossy(QueueElementIF enqueueMe)
Description copied from interface: SinkIF
Enqueues the given element onto the queue. This is lossy in that this method drops the element if the element could not be enqueued, rather than throwing a SinkFullException or SinkClosedException. This is meant as a convenience interface for "low priority" enqueue events which can be safely dropped.
Specified by:
enqueue_lossy in interface SinkIF
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
element - The QueueElementIF to enqueue
Returns:
true if the element was enqueued, false otherwise.

enqueue_many

public void enqueue_many(QueueElementIF[] enqueueMe)
                  throws SinkFullException
Description copied from interface: SinkIF
Given an array of elements, atomically enqueues all of the elements in the array. This guarantees that no other thread can interleave its own elements with those being inserted from this array. The implementation must enqueue all of the elements or none of them; if a SinkFullException or SinkClosedException is thrown, none of the elements will have been enqueued. This implies that the enqueue predicate (if any) must accept all elements in the array for the enqueue to proceed.
Specified by:
enqueue_many in interface SinkIF
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
elements - The element array to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.
SinkClosedException - Indicates that the sink is no longer being serviced.

dequeue

public QueueElementIF dequeue()
Description copied from interface: SourceIF
Dequeues the next element, or returns null if there is nothing left on the queue.
Specified by:
dequeue in interface SourceIF
Following copied from interface: seda.sandStorm.api.SourceIF
Returns:
the next QueueElementIF on the queue

dequeue_all

public QueueElementIF[] dequeue_all()
Description copied from interface: SourceIF
Dequeues all available elements, or returns null if there is nothing left on the queue.
Specified by:
dequeue_all in interface SourceIF
Following copied from interface: seda.sandStorm.api.SourceIF
Returns:
all pending QueueElementIFs on the queue

dequeue

public QueueElementIF[] dequeue(int num)
Description copied from interface: SourceIF
Dequeues at most num available elements, or returns null if there is nothing left on the queue.
Specified by:
dequeue in interface SourceIF
Following copied from interface: seda.sandStorm.api.SourceIF
Returns:
At most num QueueElementIFs on the queue

dequeue

public QueueElementIF[] dequeue(int num,
                                boolean mustReturnNum)

blocking_dequeue_all

public QueueElementIF[] blocking_dequeue_all(int timeout_millis)
Description copied from interface: SourceIF
This method blocks on the queue up until a timeout occurs or until an element appears on the queue. It returns all elements waiting on the queue at that time.
Specified by:
blocking_dequeue_all in interface SourceIF
Following copied from interface: seda.sandStorm.api.SourceIF
Parameters:
timeout_millis - if timeout_millis is 0, this method will be non-blocking and will return right away, whether or not any elements are pending on the queue. If timeout_millis is -1, this method blocks forever until something is available. If timeout_millis is positive, this method will wait about that number of milliseconds before returning, but possibly a little more.
Returns:
an array of QueueElementIF's. This array will be null if no elements were pending.

blocking_dequeue

public QueueElementIF[] blocking_dequeue(int timeout_millis,
                                         int num,
                                         boolean mustReturnNum)

blocking_dequeue

public QueueElementIF[] blocking_dequeue(int timeout_millis,
                                         int num)
Description copied from interface: SourceIF
This method blocks on the queue up until a timeout occurs or until an element appears on the queue. It returns at most num elements waiting on the queue at that time.
Specified by:
blocking_dequeue in interface SourceIF

blocking_dequeue

public QueueElementIF blocking_dequeue(int timeout_millis)
Description copied from interface: SourceIF
Just like blocking_dequeue_all, but returns only a single element.
Specified by:
blocking_dequeue in interface SourceIF

profileSize

public int profileSize()
Return the profile size of the queue.
Specified by:
profileSize in interface ProfilableIF

enqueue_prepare

public java.lang.Object enqueue_prepare(QueueElementIF[] enqueueMe)
                                 throws SinkException
Provisionally enqueue the given elements.
Specified by:
enqueue_prepare in interface SinkIF
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
elements - The element array to provisionally enqueue
Returns:
A "transaction key" that may be used to commit or abort the provisional enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full and that the requested elements could not be provisionally enqueued.
SinkClosedException - Indicates that the sink is no longer being serviced.
See Also:
enqueue_commit, enqueue_abort

enqueue_commit

public void enqueue_commit(java.lang.Object key)
Commit a provisional enqueue.
Specified by:
enqueue_commit in interface SinkIF
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
key - The enqueue key returned by a previous call to enqueue_prepare().
Throws:
java.lang.IllegalArgumentException - Thrown if an unknown enqueue key is provided.

enqueue_abort

public void enqueue_abort(java.lang.Object key)
Abort a provisional enqueue.
Specified by:
enqueue_abort in interface SinkIF
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
key - The enqueue key returned by a previous call to enqueue_prepare().
Throws:
java.lang.IllegalArgumentException - Thrown if an unknown enqueue key is provided.

setEnqueuePredicate

public void setEnqueuePredicate(EnqueuePredicateIF pred)
Set the enqueue predicate for this sink.
Specified by:
setEnqueuePredicate in interface SinkIF

getEnqueuePredicate

public EnqueuePredicateIF getEnqueuePredicate()
Return the enqueue predicate for this sink.
Specified by:
getEnqueuePredicate in interface SinkIF

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

More information: http://www.cs.berkeley.edu/~mdw/proj/seda/