Class WindowQueue

java.lang.Object
com.webmethods.rtl.event.WindowQueue
All Implemented Interfaces:
Cloneable

public class WindowQueue extends Object implements Cloneable
A queue implemented using a cicular buffer that holds a finite number of elements. When an item is added to the queue and the queue is full, the first element is removed to make room. This simulates a sliding window queue. On the get() method, the call is blocked if the queue is empty until data is added.

All methods in this class run explicitly or implicitly synchronized on the object.

Most of the methods in this class are also declared final so they can be more readily in-lined by the compiler.

Copyright (c) 2002-2005 webMethods, Inc. This class is based largely on the WindowQueue class

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The exception to be throw to kick the blocking get() call when the queue is shutdown().
  • Constructor Summary

    Constructors
    Constructor
    Description
    Contructs a windowed queue with a default beginning size.
    WindowQueue(int size)
    Contructs a queue with an initial size.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Object
    Clones this object.
    final Object
    get()
    Gets an object from the queue.
    final Object
    get(int timeoutMs)
    Gets an object from the queue.
    final boolean
    Tests if the queue is empty.
    final boolean
    Tests if the queue is full.
    final Object
    Peeks an object from the queue.
    final void
    put(Object obj)
    Adds an object to the queue.
    void
    Shuts down the queue.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WindowQueue

      public WindowQueue()
      Contructs a windowed queue with a default beginning size.
    • WindowQueue

      public WindowQueue(int size)
      Contructs a queue with an initial size.
      Parameters:
      size - the size of the queue, must be > 0. If it is <=0, it is ignored and the default size is used
  • Method Details

    • clone

      protected Object clone()
      Clones this object.
      Overrides:
      clone in class Object
      Returns:
      a copy of this queue
    • put

      public final void put(Object obj)
      Adds an object to the queue. If the queue is full, the queue is expanded if it is resizable. If the queue if not resizable, or if there is no more memory to expand the queue, the calling thread is blocked until items has been removed from the queue by another thread calling get().

      If this call is interrupted/terminated by shutdown(), the object may be discarded and the call returns without put it on the queue.

      Parameters:
      obj - the Object to add to the queue
    • get

      public final Object get() throws WindowQueue.ShutdownException
      Gets an object from the queue. If queue is empty, the calling thread is blocked until an entry is added to the queue by another thread.
      Returns:
      the next object on the queue
      Throws:
      WindowQueue.ShutdownException - WindowQueue.ShutdownException, if this call is interrupted/terminated by shutdown()
    • get

      public final Object get(int timeoutMs) throws WindowQueue.ShutdownException
      Gets an object from the queue. If queue is empty, the calling thread is blocked until an entry is added to the queue by another thread or the specified timeout is exceeded
      Parameters:
      timeoutMs - - maximum time to wait before returning (null is returned for timeout)
      Returns:
      the next object on the queue
      Throws:
      WindowQueue.ShutdownException - WindowQueue.ShutdownException, if this call is interrupted/terminated by shutdown()
    • peek

      public final Object peek() throws WindowQueue.ShutdownException
      Peeks an object from the queue. If queue is empty, the calling thread is blocked until an entry is added to the queue by another thread. As opposed to get() function peek() won't remove an item from the queue
      Returns:
      the next object on the queue
      Throws:
      WindowQueue.ShutdownException - WindowQueue.ShutdownException, if this call is interrupted/terminated by shutdown()
    • isFull

      public final boolean isFull()
      Tests if the queue is full.
      Returns:
      true if the queue is full
    • isEmpty

      public final boolean isEmpty()
      Tests if the queue is empty.
      Returns:
      true if the queue is empty
    • shutdown

      public void shutdown()
      Shuts down the queue. It sets the internal shutdown flag of the queue, then wakes up all threads waiting to put(java.lang.Object) or get() which would then abort their current operation.