org.opennms.core.queue
Interface FifoQueue<T>

All Known Subinterfaces:
BoundedFifoQueue<T>, ClosableFifoQueue<T>, NotifiableInputFifoQueue<T>, NotifiableOutputFifoQueue<T>
All Known Implementing Classes:
FifoQueueImpl, LegacyScheduler.PeekableFifoQueue, Scheduler.PeekableFifoQueue

public interface FifoQueue<T>

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.

Version:
$Id: $
Author:
Brian Weaver , OpenNMS , Brian Weaver , OpenNMS

Method Summary
 void add(T element)
          Inserts a new element into the queue.
 boolean add(T element, long timeout)
          Inserts a new element into the queue.
 boolean isEmpty()
          Used to test if the current queue has no stored elements.
 T remove()
          Removes the oldest element from the queue.
 T 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.
 

Method Detail

add

void add(T element)
         throws FifoQueueException,
                InterruptedException
Inserts a new element into the queue.

Type Parameters:
T - a T object.
Parameters:
element - The object to append to the queue.
Throws:
FifoQueueException - Thrown if a queue error occurs.
InterruptedException - Thrown if the thread is interrupted.
FifoQueueException - if any.
InterruptedException - if any.

add

boolean add(T element,
            long timeout)
            throws FifoQueueException,
                   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.

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.
InterruptedException - Thrown if the thread is interrupted.
UnsupportedOperationException - Thrown if the method is not supported.
FifoQueueException - if any.
InterruptedException - if any.

remove

T remove()
         throws FifoQueueException,
                InterruptedException
Removes the oldest element from the queue.

Returns:
The oldest object in the queue.
Throws:
FifoQueueException - Thrown if a queue error occurs.
InterruptedException - Thrown if the thread is interrupted.
FifoQueueException - if any.
InterruptedException - if any.

remove

T remove(long timeout)
         throws FifoQueueException,
                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.

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.
InterruptedException - Thrown if the thread is interrupted.
UnsupportedOperationException - Thrown if the method is not supported.
FifoQueueException - if any.
InterruptedException - if any.

size

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

Returns:
The number of elements in the queue.

isEmpty

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

Returns:
True if the queue is empty.


Copyright © 2011. All Rights Reserved.