|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.d_haven.event.impl.MultiCastSink
public class MultiCastSink
This is a Sink
implementation that
multicasts enqueue operations to the contained and concrete sink
objects. The multi cast sink will try to enqueue and only succeeds
if no element was rejected from any sink. The sink can be configured
to enqueue into one sink alone or all sinks. If a sink array in the
collection of sinks contains more than one sink the multicast sink
will try to enqueue the element always to only one of these
sinks.
Nested Class Summary | |
---|---|
private static class |
MultiCastSink.MultiCastPreparedEnqueue
A prepared enqueue object that holds other prepared enqueue objects and allows to perform a commit / abort on all of these objects. |
Field Summary | |
---|---|
private boolean |
m_single
Boolean value describing if one or all operations must succeed. |
private java.util.Collection |
m_sinks
A collection of sink arrays representing the sinks to enqueue to. |
Constructor Summary | |
---|---|
MultiCastSink(java.util.Collection sinks)
This constructor creates a failure in-tolerant multicast sink based on the collection of sink arrays. |
|
MultiCastSink(java.util.Collection sinks,
boolean single)
This constructor creates a failure in-tolerant multicast sink based on the collection of sink arrays. |
Method Summary | |
---|---|
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. |
PreparedEnqueue |
prepareEnqueue(java.lang.Object[] elements)
Support for transactional enqueue. |
int |
size()
Returns the number of elements waiting in this Sink. |
java.lang.String |
toString()
|
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, wait, wait, wait |
Field Detail |
---|
private final java.util.Collection m_sinks
private final boolean m_single
Constructor Detail |
---|
public MultiCastSink(java.util.Collection sinks)
sinks
- A collection of sink arrays for each stage.public MultiCastSink(java.util.Collection sinks, boolean single)
sinks
- A collection of sink arrays for each stage.single
- Method Detail |
---|
public void enqueue(java.lang.Object element) throws SinkException
Sink
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
public void enqueue(java.lang.Object[] elements) throws SinkException
Sink
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
public boolean tryEnqueue(java.lang.Object element)
Sink
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
Sink
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
public int size()
Sink
Important: The contract for this method was updated to account for any elements that were prepared for enqueueing. It provides a more predictable and consistent environment, as well as making it easier for EnqueuePredicates to account for those elements.
size
in interface Sink
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |