|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A Source implements the end of a finite-length event queue where QueueElements are enqueued. These operations can throw a SourceException if the sink is closed or becomes full, allowing event queues to support thresholding and backpressure.
Method Summary | |
int |
canAccept()
Returns the number of QueueElements it can currently accept. |
void |
enqueue(QueueElement element)
Enqueues the given element onto the queue. |
void |
enqueue(QueueElement[] elements)
Given an array of elements, atomically enqueues all of the elements in the array. |
boolean |
isFull()
Returns true if this sink has reached its threshold; false otherwise. |
int |
maxSize()
Returns the length threshold of the sink. |
PreparedEnqueue |
prepareEnqueue(QueueElement[] elements)
Support for transactional enqueue. |
int |
size()
Returns the number of elements waiting in this queue. |
boolean |
tryEnqueue(QueueElement element)
Tries to enqueue an event, but instead of throwing exceptions, it returns a boolean value of whether the attempt was successful. |
Method Detail |
public void enqueue(QueueElement element) throws SourceException
element
- The QueueElement
to enqueueSourceFullException
- Indicates that the sink is temporarily full.SourceClosedException
- Indicates that the sink is
no longer being serviced.public void enqueue(QueueElement[] elements) throws SourceException
elements
- The element array to enqueueSourceFullException
- Indicates that the sink is temporarily full.SourceClosedException
- Indicates that the sink is
no longer being serviced.public boolean tryEnqueue(QueueElement element)
element
- The element to attempt to enqueuetrue
if successful, false
if not.public PreparedEnqueue prepareEnqueue(QueueElement[] elements) throws SourceException
This 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 anabortEnqueue
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 queues.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
Throws:SourceFullException
- Indicates that the sink is temporarily full
and that the requested elements could not be provisionally
enqueued.SourceClosedException
- Indicates that the sink is
no longer being serviced.PreparedEnqueue
public int size()
public int maxSize()
public boolean isFull()
public int canAccept()
size()
and
maxSize()
. It will return -1 if the queue is unbounded.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |