OpenNMS API 1.2.9

## org.opennms.core.concurrent
Class RunnableConsumerThreadPool.SizingFifoQueue

    java.lang.Object
      org.opennms.core.queue.FifoQueueImpl
          org.opennms.core.concurrent.RunnableConsumerThreadPool.SizingFifoQueue

All Implemented Interfaces:
  ClosableFifoQueue, FifoQueue

Enclosing class:
  RunnableConsumerThreadPool

private class RunnableConsumerThreadPool.SizingFifoQueue
extends FifoQueueImpl
implements ClosableFifoQueue

This class is used to create a queue that auto adjust the number of threads in the pool. Each time an addition or removal of queue elements occur the pool will be adjusted. This will cause some synchronization overhead, but it should be correct implementation.

To avoid the condition of toggleing a single thread the lo and hi water marks should have a large cushion between them.

Author:
  Brian Weaver , OpenNMS

Field Summary
`private boolean` `m_isClosed` Determines if the queue is open or closed.

Fields inherited from class org.opennms.core.queue.FifoQueueImpl
``

Constructor Summary
`private` `RunnableConsumerThreadPool.SizingFifoQueue()`

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.
`private void` `adjust()` Adjust the size of the thread pool based on the ratio of queue elements to threads.
`void` `close()` Closes a currently open queue.
`boolean` `isClosed()` Returns true if the queue is currently closed.
`boolean` `isOpen()` Returns true if the queue is currently open.
`void` `open()` Ensures that the queue is open and new elements can be added to the queue.
`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.

Methods inherited from class org.opennms.core.queue.FifoQueueImpl
`isEmpty, size`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface org.opennms.core.queue.FifoQueue
`isEmpty, size`

Field Detail

### m_isClosed

    private volatile boolean m_isClosed

  Determines if the queue is open or closed. If the queue is closed then an exception is thrown on queue additions. Also, queue removals will cause a queue exception if the queue is empty.

Constructor Detail

### RunnableConsumerThreadPool.SizingFifoQueue

    private RunnableConsumerThreadPool.SizingFifoQueue()

Method Detail

### adjust

    private void adjust()

  Adjust the size of the thread pool based on the ratio of queue elements to threads. The thread pool is adjusted by the lo and hi water marks which are a ratio of elements to threads.

### isOpen

    public boolean isOpen()

  Returns true if the queue is currently open.

  Specified by:
    `isOpen` in interface `ClosableFifoQueue`
  Returns:
    True if the queue is open.

### isClosed

    public boolean isClosed()

  Returns true if the queue is currently closed.

  Specified by:
    `isClosed` in interface `ClosableFifoQueue`
  Returns:
    True if the queue is closed.

### close

    public void close()
               throws FifoQueueException

  Closes a currently open queue. When a queue is closed is should still allow elements already in the queue to be removed, but new elements should not be added.

  Specified by:
    `close` in interface `ClosableFifoQueue`
  Throws:
    `FifoQueueException` - Thrown if an error occurs closing the queue.

### open

    public void open()
              throws FifoQueueException

  Ensures that the queue is open and new elements can be added to the queue.

  Specified by:
    `open` in interface `ClosableFifoQueue`
  Throws:
    `FifoQueueException` - Thrown if an error occurs opening the queue.

### 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`
  Overrides:
    `add` in class `FifoQueueImpl`
  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`
  Overrides:
    `add` in class `FifoQueueImpl`
  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`
  Overrides:
    `remove` in class `FifoQueueImpl`
  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`
  Overrides:
    `remove` in class `FifoQueueImpl`
  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.

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.