Package com.webmethods.rtl.event
Class BufferingQueue
java.lang.Object
com.webmethods.rtl.event.BufferingQueue
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The exception to be throw to kick the blockingget()
call when the queue isshutdown()
. -
Constructor Summary
ConstructorsConstructorDescriptionContructs a resizable queue with a default beginning size.BufferingQueue
(int size) Constructs a non-resizble queue with the specified size.BufferingQueue
(int size, boolean resizable) Contructs a queue with an initial size.BufferingQueue
(BufferingQueue another) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
clone()
Clones this object.final Object
get()
Gets an object from the queue.final boolean
isEmpty()
Tests if the queue is empty.final boolean
isFull()
Tests if the queue is full.final Object
peek()
Peeks an object from the queue.final void
Adds an object to the queue.void
shutdown()
Shuts down the queue.
-
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 usedresizble
- specifies if the queue is resizable
-
BufferingQueue
Deprecated.use theclone()
method to do the copyingCopy ctor.- Parameters:
another
- the other object to copy from
-
-
Method Details
-
clone
Clones this object. -
put
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 callingget()
.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
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
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 toput(java.lang.Object)
orget()
which would then abort their current operation.
-
clone()
method to do the copying