|
Keel 2.1RC2 | ||||||||||
| 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.FixedSizeQueue
An implementation of the Queue that has a fixed size. Once the maximum number of elements are set, this Queue cannot be changed.
| Nested Class Summary | |
private static class |
FixedSizeQueue.FixedSizePreparedEnqueueDeprecated. |
| Field Summary | |
private java.lang.Object[] |
m_elementsDeprecated. |
private int |
m_endDeprecated. |
private ReentrantLock |
m_mutexDeprecated. |
protected int |
m_reserveDeprecated. |
private int |
m_startDeprecated. |
| 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 | |
FixedSizeQueue(int size)Deprecated. Create a FixedSizedQueue with the specified maximum size. |
|
| Method Summary | |
private void |
addElement(java.lang.Object element)Deprecated. |
java.lang.Object |
dequeue()Deprecated. 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)Deprecated. Dequeues at most num available elements. |
java.lang.Object[] |
dequeueAll()Deprecated. Dequeues all available elements. |
void |
enqueue(java.lang.Object element)Deprecated. Enqueues the given element onto the Sink. |
void |
enqueue(java.lang.Object[] elements)Deprecated. Given an array of elements, atomically enqueues all of the elements in the array. |
int |
maxSize()Deprecated. Default maxSize to -1 which is unbounded |
PreparedEnqueue |
prepareEnqueue(java.lang.Object[] elements)Deprecated. Support for transactional enqueue. |
private java.lang.Object |
removeElement()Deprecated. |
private java.lang.Object[] |
retrieveElements(int count)Deprecated. Removes exactly count elements from the underlying element store and returns them as an array of Objects. |
int |
size()Deprecated. Returns the number of elements waiting in this Source. |
boolean |
tryEnqueue(java.lang.Object element)Deprecated. 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 |
private final java.lang.Object[] m_elements
private final ReentrantLock m_mutex
private int m_start
private int m_end
protected int m_reserve
| Constructor Detail |
public FixedSizeQueue(int size)
FixedSizedQueue with the specified maximum size. The maximum size must be 1 or more.
size - The maximum number of events the Queue can handle| Method Detail |
public int size()
Sourcepublic int maxSize()
AbstractQueuemaxSize in interface SinkmaxSize in class AbstractQueue
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 enqueuePreparedEnqueue that may be used to commit or abort the provisional enqueueSinkExceptionPreparedEnqueuepublic boolean tryEnqueue(java.lang.Object element)
Sinkelement - The element to attempt to enqueuetrue if successful, false if not.
public void enqueue(java.lang.Object[] elements)
throws SinkException
Sinkelements - The element array to enqueueSinkException
public void enqueue(java.lang.Object element)
throws SinkException
Sinkelement - The elements to enqueueSinkExceptionpublic 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 dequeuenum elements from the Sourceprivate final void addElement(java.lang.Object element)
private final java.lang.Object removeElement()
private final java.lang.Object[] retrieveElements(int count)
count elements from the underlying element store and returns them as an array of Objects. The caller is responsible for synchronizing access to the element store and passing the correct value for count.
The method can be further optimized by using System.arraycopy if it is found to underperform.
count - number of elements to returnpublic java.lang.Object[] dequeueAll()
Sourcepublic 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
|
Keel 2.1RC2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||