Package com.webmethods.rtl.event
Class WindowQueue
java.lang.Object
com.webmethods.rtl.event.WindowQueue
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescriptionstatic class
The exception to be throw to kick the blockingget()
call when the queue isshutdown()
. -
Constructor Summary
ConstructorsConstructorDescriptionContructs a windowed queue with a default beginning size.WindowQueue
(int size) Contructs a queue with an initial size. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
clone()
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
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
-
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
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:
WindowQueue.ShutdownException
-WindowQueue.ShutdownException
, if this call is interrupted/terminated byshutdown()
-
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 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 byshutdown()
-
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:
WindowQueue.ShutdownException
-WindowQueue.ShutdownException
, if this call is interrupted/terminated byshutdown()
-
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.
-