|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.d_haven.event.impl.AbstractPipe
public abstract class AbstractPipe
Provides the base functionality for the other Pipe
types.
Field Summary | |
---|---|
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 Summary | |
---|---|
AbstractPipe()
|
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 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.d_haven.event.Source |
---|
size |
Methods inherited from interface org.d_haven.event.Sink |
---|
size |
Field Detail |
---|
protected long m_timeout
protected java.lang.Object m_lock
protected EnqueuePredicate m_predicate
protected DequeueInterceptor m_interceptor
Constructor Detail |
---|
public AbstractPipe()
Method Detail |
---|
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 Source
millis
- The number of milliseconds to block waiting for
events to be enqueuedpublic void setEnqueuePredicate(EnqueuePredicate predicate)
setEnqueuePredicate
in interface Pipe
predicate
- the predicate to begin usingpublic EnqueuePredicate getEnqueuePredicate()
getEnqueuePredicate
in interface Pipe
public void setDequeueInterceptor(DequeueInterceptor executable)
setDequeueInterceptor
in interface Pipe
executable
- The dequeue executable for this sink.public DequeueInterceptor getDequeueInterceptor()
getDequeueInterceptor
in interface Pipe
DequeueInterceptor
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.
dequeue
in interface Source
protected abstract java.lang.Object doDequeue()
public java.lang.Object[] dequeueAll()
dequeueAll
in interface Source
protected 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.
dequeue
in interface Source
num
- The maximum number of elements to dequeue
num
elements from the Sourceprotected abstract java.lang.Object[] doDequeue(int num)
num
- the number of elements to dequeue
public void enqueue(java.lang.Object element) throws SinkException
enqueue
in interface Sink
element
- The elements to enqueue
SinkFullException
- Indicates that the sink is temporarily full.
SinkClosedException
- Indicates that the sink is no longer being serviced.
SinkException
protected abstract void doEnqueue(java.lang.Object element) throws SinkException
element
- the event to enqueue
SinkException
- if there is a problem beyond the initial
validation.public void enqueue(java.lang.Object[] elements) throws SinkException
enqueue
in interface Sink
elements
- The element array to enqueue
SinkFullException
- Indicates that the sink is temporarily full.
SinkClosedException
- Indicates that the sink is no longer being serviced.
SinkException
protected abstract void doEnqueue(java.lang.Object[] elements) throws SinkException
elements
- the events to enqueue
SinkException
- if there is a problem beyond the initial
validation.public boolean tryEnqueue(java.lang.Object element)
tryEnqueue
in interface Sink
element
- The element to attempt to enqueue
true
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 Sink
elements
- The element array to provisionally enqueue
PreparedEnqueue
that may be used to commit
or abort the provisional enqueue
SinkFullException
- 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.
SinkException
PreparedEnqueue
protected abstract PreparedEnqueue doPrepareEnqueue(java.lang.Object[] elements) throws SinkException
elements
- the events to enqueue
SinkException
- if there is a problem beyond the initial
validation.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |