|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.apache.excalibur.event.impl.AbstractQueue
org.apache.excalibur.event.impl.DefaultQueue
The default queue implementation is a variable size queue. This queue is thread safe, however the overhead in synchronization costs a few extra milliseconds.
| Field Summary | |
protected int |
m_reserve
|
| Fields inherited from class org.apache.excalibur.event.impl.AbstractQueue |
EMPTY_ARRAY, m_interceptor, m_predicate, m_timeout |
| Fields inherited from interface org.apache.excalibur.event.Queue |
ROLE |
| Constructor Summary | |
DefaultQueue()
Create an unbounded DefaultQueue. |
|
DefaultQueue(EnqueuePredicate predicate)
|
|
DefaultQueue(int size)
Construct a new DefaultQueue with the specified number of elements. |
|
| Method Summary | |
java.lang.Object |
dequeue()
Dequeues the next element, or null if there is
nothing left on the queue or in case of a timeout while
attempting to obtain the mutex |
java.lang.Object[] |
dequeue(int numElements)
Dequeues at most num available elements. |
java.lang.Object[] |
dequeueAll()
Dequeues all available elements. |
void |
enqueue(java.lang.Object element)
Enqueues the given element onto the Sink. |
void |
enqueue(java.lang.Object[] elements)
Given an array of elements, atomically enqueues all of the elements in the array. |
int |
maxSize()
Return the maximum number of elements that will fit in the Queue. |
PreparedEnqueue |
prepareEnqueue(java.lang.Object[] elements)
Support for transactional enqueue. |
int |
size()
Return the number of elements currently in the Queue. |
boolean |
tryEnqueue(java.lang.Object element)
Tries to enqueue an event, but instead of throwing exceptions, it returns a boolean value of whether the attempt was successful. |
| Methods inherited from class org.apache.excalibur.event.impl.AbstractQueue |
block, canAccept, getDequeueInterceptor, getEnqueuePredicate, isFull, setDequeueInterceptor, setEnqueuePredicate, setTimeout |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected int m_reserve
| Constructor Detail |
public DefaultQueue(int size)
Queue is bounded by that number. Otherwise, the
Queue is not bounded at all.
size - The maximum number of elements in the Queue.
Any number less than 1 means there is no limit.public DefaultQueue(EnqueuePredicate predicate)
public DefaultQueue()
| Method Detail |
public int size()
Queue.
int representing the number of elements (including the reserved ones).public int maxSize()
Queue. A number below 1 indecates an unbounded
Queue, which means there is no limit.
maxSize in interface SinkmaxSize in class AbstractQueueint representing the maximum number of elements
public PreparedEnqueue prepareEnqueue(java.lang.Object[] elements)
throws SinkException
SinkThis method allows a client to provisionally enqueue a number
of elements onto the queue, and then later commit the enqueue (with
a commitEnqueue call), or abort (with an
abortEnqueue call). This mechanism can be used to
perform "split-phase" enqueues, where a client first enqueues a
set of elements on the queue and then performs some work to "fill in"
those elements before performing a commit. This can also be used
to perform multi-queue transactional enqueue operations, with an
"all-or-nothing" strategy for enqueueing events on multiple Sinks.
This method would generally be used in the following manner:
PreparedEnqueue enqueue = sink.prepareEnqueue(someElements);
if (canCommit) {
enqueue.commit();
} else {
enqueue.abort();
}
Note that this method does not protect against "dangling prepares" -- that is, a prepare without an associated commit or abort operation. This method should be used with care. In particular, be sure that all code paths (such as exceptions) after a prepare include either a commit or an abort.
elements - The element array to provisionally enqueue
PreparedEnqueue that may be used to commit or
abort the provisional enqueue
SinkExceptionPreparedEnqueuepublic boolean tryEnqueue(java.lang.Object element)
Sink
element - The element to attempt to enqueue
true if successful, false if not.
public void enqueue(java.lang.Object[] elements)
throws SinkException
Sink
elements - The element array to enqueue
SinkException
public void enqueue(java.lang.Object element)
throws SinkException
Sink
element - The elements to enqueue
SinkExceptionpublic java.lang.Object[] dequeue(int numElements)
Sourcenum available elements. Returns a
zero-sized array in case of a timeout while attempting to
obtain the mutex or if there is nothing left on the Source.
numElements - The maximum number of elements to dequeue
num elements from the
Sourcepublic java.lang.Object[] dequeueAll()
Source
public java.lang.Object dequeue()
Sourcenull if there is
nothing left on the queue or in case of a timeout while
attempting to obtain the mutex
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||