public abstract class AbstractPipe extends java.lang.Object implements Pipe
Pipe
types.| Modifier and Type | Field and Description |
|---|---|
protected DequeueInterceptor |
m_interceptor
The DequeueInterceptor used.
|
protected java.lang.Object |
m_lock
The lock used to delay entries.
|
protected EnqueuePredicate |
m_predicate
The EnqueuePredicate used.
|
protected long |
m_timeout
The number of milliseconds to wait.
|
| Constructor and Description |
|---|
AbstractPipe() |
| Modifier and Type | Method and Description |
|---|---|
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 num)
Dequeues at most
num available elements. |
java.lang.Object[] |
dequeueAll()
Dequeues all available elements.
|
protected abstract java.lang.Object |
doDequeue()
Abstract method to allow child classes to only focus on the part
necessary to dequeue one event.
|
protected abstract java.lang.Object[] |
doDequeue(int num)
Abstract method to allow child classes to only focus on the part
necessary to dequeue the supplied number of events.
|
protected abstract java.lang.Object[] |
doDequeueAll()
Abstract method to allow child classes to only focus on the part
necessary to dequeue the remaining events.
|
protected abstract void |
doEnqueue(java.lang.Object element)
Abstract method provided to allow the child classes to focus only
on the portion of code needed to enqueue one event.
|
protected abstract void |
doEnqueue(java.lang.Object[] elements)
Abstract method provided to allow the child classes to focus only
on the portion of code needed to enqueue the supplied events.
|
protected abstract PreparedEnqueue |
doPrepareEnqueue(java.lang.Object[] elements)
Abstract method provided to allow the child classes to focus only
on the portion of code needed to do a prepared enqueue for the
supplied events.
|
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.
|
DequeueInterceptor |
getDequeueInterceptor()
Return the dequeue executable for this sink.
|
EnqueuePredicate |
getEnqueuePredicate()
Return the EnqueuePredicate that is already set for this Pipe.
|
PreparedEnqueue |
prepareEnqueue(java.lang.Object[] elements)
Support for transactional enqueue.
|
void |
setDequeueInterceptor(DequeueInterceptor executable)
Set the dequeue executable for this sink.
|
void |
setEnqueuePredicate(EnqueuePredicate predicate)
Set the EnqueuePredicate to limit entries into this Pipe.
|
void |
setTimeout(long millis)
Set the timeout for the
Pipe in milliseconds. |
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.
|
protected long m_timeout
protected java.lang.Object m_lock
protected EnqueuePredicate m_predicate
protected DequeueInterceptor m_interceptor
public void setTimeout(long millis)
Pipe in milliseconds. The
default timeout is 0, which means that we don't wait at all.setTimeout in interface Sourcemillis - The number of milliseconds to block waiting for
events to be enqueuedpublic void setEnqueuePredicate(EnqueuePredicate predicate)
setEnqueuePredicate in interface Pipepredicate - the predicate to begin usingpublic EnqueuePredicate getEnqueuePredicate()
getEnqueuePredicate in interface Pipepublic void setDequeueInterceptor(DequeueInterceptor executable)
setDequeueInterceptor in interface Pipeexecutable - The dequeue executable for this sink.public DequeueInterceptor getDequeueInterceptor()
getDequeueInterceptor in interface PipeDequeueInterceptor The dequeue executable for
this sink.public java.lang.Object dequeue()
null if there is
nothing left on the queue or in case of a timeout while
attempting to obtain the mutex.protected abstract java.lang.Object doDequeue()
public java.lang.Object[] dequeueAll()
dequeueAll in interface Sourceprotected abstract java.lang.Object[] doDequeueAll()
public java.lang.Object[] dequeue(int num)
num 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.protected abstract java.lang.Object[] doDequeue(int num)
num - the number of elements to dequeuepublic void enqueue(java.lang.Object element)
throws SinkException
enqueue in interface Sinkelement - The elements to enqueueSinkFullException - Indicates that the sink is temporarily full.SinkClosedException - Indicates that the sink is no longer being serviced.SinkExceptionprotected abstract void doEnqueue(java.lang.Object element)
throws SinkException
element - the event to enqueueSinkException - if there is a problem beyond the initial
validation.public void enqueue(java.lang.Object[] elements)
throws SinkException
enqueue in interface Sinkelements - The element array to enqueueSinkFullException - Indicates that the sink is temporarily full.SinkClosedException - Indicates that the sink is no longer being serviced.SinkExceptionprotected abstract void doEnqueue(java.lang.Object[] elements)
throws SinkException
elements - the events to enqueueSinkException - if there is a problem beyond the initial
validation.public boolean tryEnqueue(java.lang.Object element)
tryEnqueue in interface Sinkelement - The element to attempt to enqueuetrue if successful, false if
not.public PreparedEnqueue prepareEnqueue(java.lang.Object[] elements) throws SinkException
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 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.
prepareEnqueue in interface Sinkelements - The element array to provisionally enqueuePreparedEnqueue that may be used to commit
or abort the provisional enqueueSinkFullException - Indicates that the sink is temporarily full and that the
requested elements could not be provisionally enqueued.SinkClosedException - Indicates that the sink is no longer being serviced.SinkExceptionPreparedEnqueueprotected abstract PreparedEnqueue doPrepareEnqueue(java.lang.Object[] elements) throws SinkException
elements - the events to enqueueSinkException - if there is a problem beyond the initial
validation.