Class BufferingQueue

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

public class BufferingQueue extends Object implements Cloneable
A queue implemented using a cicular buffer. The buffer may be resizable. If the buffer is not resizable and when it is full, the put() operation will be blocked until space is freed up. 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-2003 webMethods, Inc.

  • Constructor Details

    • BufferingQueue

      public BufferingQueue()
      Contructs a resizable queue with a default beginning size.
    • BufferingQueue

      public BufferingQueue(int size)
      Constructs a non-resizble queue with the specified size.
      Parameters:
      size - the size of the queue, must be > 0. If it is <=0, it is ignored and the default constructor is call to contruct a resizable queue.
    • BufferingQueue

      public BufferingQueue(int size, boolean resizable)
      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
      resizble - specifies if the queue is resizable
    • BufferingQueue

      public BufferingQueue(BufferingQueue another)
      Deprecated.
      use the clone() method to do the copying
      Copy ctor.
      Parameters:
      another - the other object to copy from
  • 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 BufferingQueue.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:
      BufferingQueue.ShutdownException
    • peek

      public final Object peek() throws BufferingQueue.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:
      BufferingQueue.ShutdownException
    • 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.