guarana.toolkit.engine
Class WorkQueue

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue<E>
          extended by java.util.concurrent.PriorityBlockingQueue<WorkUnit>
              extended by guarana.toolkit.engine.WorkQueue
All Implemented Interfaces:
Serializable, Iterable<WorkUnit>, Collection<WorkUnit>, BlockingQueue<WorkUnit>, Queue<WorkUnit>

public class WorkQueue
extends PriorityBlockingQueue<WorkUnit>

A priority queue that contains work units ready to be executed.

Since:
Guaranį SDK 1.0.0
Author:
Rafael Z. Frantz
See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
WorkQueue()
          Constructs a new work queue.
 
Method Summary
 boolean add(WorkUnit element)
          Adds an element to this queue.
 Set<String> getQueuedTaskNames()
          Returns all the names of tasks waiting in this queue.
 WorkUnit poll()
          Polls an element from the queue.
 int releaseWaitingThreads()
          Releases all threads which have polled this queue and are waiting for an element.
 
Methods inherited from class java.util.concurrent.PriorityBlockingQueue
clear, comparator, contains, drainTo, drainTo, iterator, offer, offer, peek, poll, put, remainingCapacity, remove, size, take, toArray, toArray, toString
 
Methods inherited from class java.util.AbstractQueue
addAll, element, remove
 
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

WorkQueue

public WorkQueue()
Constructs a new work queue.

Method Detail

add

public boolean add(WorkUnit element)
            throws InvalidParameterException
Adds an element to this queue.

Specified by:
add in interface Collection<WorkUnit>
Specified by:
add in interface BlockingQueue<WorkUnit>
Specified by:
add in interface Queue<WorkUnit>
Overrides:
add in class PriorityBlockingQueue<WorkUnit>
Parameters:
element - The element to be added to this queue.
Returns:
boolean to indicate if the element could be added.
Throws:
InvalidParameterException - if the parameter is null.

poll

public WorkUnit poll()
Polls an element from the queue. This method also removes the element from this queue. A call to this method will block the caller till an element can be returned or till the system stops by calling releaseWaitingThreads().

Specified by:
poll in interface Queue<WorkUnit>
Overrides:
poll in class PriorityBlockingQueue<WorkUnit>
Returns:
the polled element or null in case there is no more elements and releaseWaitingThreads() is called.
See Also:
releaseWaitingThreads()

releaseWaitingThreads

public int releaseWaitingThreads()
Releases all threads which have polled this queue and are waiting for an element. This method must be called when the system has stopped and no more elements will be received by this queue.

Returns:
the number of workers that were waiting.

getQueuedTaskNames

public Set<String> getQueuedTaskNames()
Returns all the names of tasks waiting in this queue.

Returns:
a list of all the task names.


Guaranį DSL Home