OpenNMS API 1.2.3

org.opennms.core.queue
Class FifoQueueImpl

java.lang.Object
  extended byorg.opennms.core.queue.FifoQueueImpl
All Implemented Interfaces:
FifoQueue
Direct Known Subclasses:
RunnableConsumerThreadPool.SizingFifoQueue, Scheduler.PeekableFifoQueue

public class FifoQueueImpl
extends java.lang.Object
implements FifoQueue

This interface defines a queue that uses F irst In, F irst O ut semantics when adding and removing objects. Each object that is added to the queue is effectively placed at the end of the list of previous elements. Each call to remove will result in the removal of the next element, or the oldest element in the queue.

Author:
Brian Weaver , OpenNMS

Field Summary
private  java.util.LinkedList m_delegate
          The delegate list where queue elements are stored.
 
Constructor Summary
FifoQueueImpl()
          Constructs a new First In, First Out queue that can be used to exchange data.
 
Method Summary
 void add(java.lang.Object element)
          Inserts a new element into the queue.
 boolean add(java.lang.Object element, long timeout)
          Inserts a new element into the queue.
 boolean isEmpty()
          Used to test if the current queue has no stored elements.
 java.lang.Object remove()
          Removes the oldest element from the queue.
 java.lang.Object remove(long timeout)
          Removes the next element from the queue if one becomes available before the timeout expires.
 int size()
          Returns the current number of elements that are in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_delegate

private java.util.LinkedList m_delegate
The delegate list where queue elements are stored. The elements are removed from the front of the list and added to the end of the list, always!

Constructor Detail

FifoQueueImpl

public FifoQueueImpl()
Constructs a new First In, First Out queue that can be used to exchange data. The implementation is thread safe and can be used to exchange data between to concurrent processes.

Method Detail

add

public void add(java.lang.Object element)
         throws FifoQueueException,
                java.lang.InterruptedException
Inserts a new element into the queue.

Specified by:
add in interface FifoQueue
Parameters:
element - The object to append to the queue.
Throws:
FifoQueueException - Thrown if a queue error occurs.
java.lang.InterruptedException - Thrown if the thread is interrupted.

add

public boolean add(java.lang.Object element,
                   long timeout)
            throws FifoQueueException,
                   java.lang.InterruptedException
Inserts a new element into the queue. If the queue has reached an implementation limit and the timeout expires, then a false value is returned to the caller.

Specified by:
add in interface FifoQueue
Parameters:
element - The object to append to the queue.
timeout - The time to wait on the insertion to succeed.
Returns:
True if the element was successfully added to the queue before the timeout expired, false otherwise.
Throws:
FifoQueueException - Thrown if a queue error occurs.
java.lang.InterruptedException - Thrown if the thread is interrupted.

remove

public java.lang.Object remove()
                        throws FifoQueueException,
                               java.lang.InterruptedException
Removes the oldest element from the queue.

Specified by:
remove in interface FifoQueue
Returns:
The oldest object in the queue.
Throws:
FifoQueueException - Thrown if a queue error occurs.
java.lang.InterruptedException - Thrown if the thread is interrupted.

remove

public java.lang.Object remove(long timeout)
                        throws FifoQueueException,
                               java.lang.InterruptedException
Removes the next element from the queue if one becomes available before the timeout expires. If the timeout expires before an element is available then a null reference is returned to the caller.

Specified by:
remove in interface FifoQueue
Parameters:
timeout - The time to wait on an object to be available.
Returns:
The oldest object in the queue, or null if one is not available.
Throws:
FifoQueueException - Thrown if a queue error occurs.
java.lang.InterruptedException - Thrown if the thread is interrupted.

size

public int size()
Returns the current number of elements that are in the queue.

Specified by:
size in interface FifoQueue
Returns:
The number of elements in the queue.

isEmpty

public boolean isEmpty()
Used to test if the current queue has no stored elements.

Specified by:
isEmpty in interface FifoQueue
Returns:
True if the queue is empty.

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.