public class ReplayingCluster extends Object implements Cluster
IncomingMessageHandler
, which defines the behavior for these events.
Replays can either be executed on the invoking thread (see startReplay()
) or asynchronously by providing an
Executor (see startReplay(java.util.concurrent.Executor)
).
Note that this cluster will replay each event on all subscribed listeners, even those that do not implement the
ReplayAware
interface. If a listener does not support replaying at all, it should not be
subscribed to either this cluster or the delegate.Constructor and Description |
---|
ReplayingCluster(Cluster delegate,
EventStoreManagement eventStore,
TransactionManager transactionManager,
int commitThreshold,
IncomingMessageHandler incomingMessageHandler)
Initializes a ReplayingCluster that wraps the given
delegate , to allow it to replay event from the
given eventStore . |
Modifier and Type | Method and Description |
---|---|
Set<EventListener> |
getMembers()
Returns a read-only view on the members in the cluster.
|
ClusterMetaData |
getMetaData()
Returns the MetaData of this Cluster.
|
String |
getName()
Returns the name of this cluster.
|
boolean |
isInReplayMode()
Indicates whether this cluster is in replay mode.
|
CriteriaBuilder |
newCriteriaBuilder()
Returns a CriteriaBuilder that allows the construction of criteria for this EventStore implementation
|
void |
publish(EventMessage... events)
Publishes the given Events to the members of this cluster.
|
void |
startReplay()
Starts a replay process on the current thread.
|
void |
startReplay(Criteria criteria)
Start a replay process on the current thread, only reading events matching the given
criteria . |
Future<Void> |
startReplay(Executor executor)
Starts a replay process using the given
executor . |
Future<Void> |
startReplay(Executor executor,
Criteria criteria)
Starts a replay process using the given
executor , only reading events matching the given
criteria . |
void |
subscribe(EventListener eventListener)
Subscribe the given
eventListener to this cluster. |
void |
subscribeEventProcessingMonitor(EventProcessingMonitor monitor)
Subscribes the given
monitor . |
void |
unsubscribe(EventListener eventListener)
Unsubscribes the given
eventListener from this cluster. |
void |
unsubscribeEventProcessingMonitor(EventProcessingMonitor monitor)
Unsubscribed the given
monitor . |
public ReplayingCluster(Cluster delegate, EventStoreManagement eventStore, TransactionManager transactionManager, int commitThreshold, IncomingMessageHandler incomingMessageHandler)
delegate
, to allow it to replay event from the
given eventStore
. The given transactionManager
is used to create a transaction for the
replay process. While in replay mode, the given incomingMessageHandler
receives all Event Messages
being published to this instance. The given commitThreshold
indicates how many events may be
processed within the same transaction. Values of 0 (zero) and negative values will prevent intermediate commits
altogether.delegate
- The cluster to add replaying capability toeventStore
- The event store providing access to events to replaytransactionManager
- The transaction manager providing the transaction for the replay processcommitThreshold
- The number of messages to process before doing an intermediate commit (0 and
negative values prevent intermediate commits)incomingMessageHandler
- The handler to receive Messages while in replay modepublic CriteriaBuilder newCriteriaBuilder()
EventStoreManagement.newCriteriaBuilder()
public void startReplay()
ReplayFailedException
- when an exception occurred during the replay processpublic void startReplay(Criteria criteria)
criteria
. This
method will return once the replay process is finished.criteria
- The criteria defining the events to replyReplayFailedException
- when an exception occurred during the replay processpublic Future<Void> startReplay(Executor executor)
executor
. The replay process itself uses a single thread.executor
- The executor to execute the replay processpublic Future<Void> startReplay(Executor executor, Criteria criteria)
executor
, only reading events matching the given
criteria
. The replay process itself uses a single thread.executor
- The executor to execute the replay processcriteria
- The criteria defining the events to replyReplayFailedException
- when an exception occurred during the replay processpublic boolean isInReplayMode()
true
if this cluster is in replay mode, false
otherwise.public String getName()
Cluster
public void publish(EventMessage... events)
Cluster
EventListeners
are
discouraged to throw exceptions, it is possible that they are propagated through this method invocation. In that
case, no guarantees can be given about the delivery of Events at all Cluster members.public void subscribe(EventListener eventListener)
eventListener
to this cluster. If the listener is already subscribed, nothing
happens.
While the Event Listeners is subscribed, it will receive all messages published to the cluster.
If the given eventListener
implements ReplayAware
, its ReplayAware.beforeReplay()
and ReplayAware.afterReplay()
methods will be invoked before and after the replay process,
respectively.
EventListeners that are subscribed while the cluster is in replay mode might receive some of the
replayed events and might not have their ReplayAware.beforeReplay()
method invoked.subscribe
in interface Cluster
eventListener
- the Event Listener instance to subscribeisInReplayMode()
public void unsubscribe(EventListener eventListener)
eventListener
from this cluster. If the listener is already unsubscribed, or was
never subscribed, nothing happens.
If the given eventListener
implements ReplayAware
and is unsubscribed during
replay, it might not have its ReplayAware.afterReplay()
method invoked when the
replay process is finished.unsubscribe
in interface Cluster
eventListener
- the Event Listener instance to unsubscribeisInReplayMode()
public Set<EventListener> getMembers()
Cluster
getMembers
in interface Cluster
public ClusterMetaData getMetaData()
Cluster
getMetaData
in interface Cluster
public void subscribeEventProcessingMonitor(EventProcessingMonitor monitor)
EventProcessingMonitorSupport
monitor
. If the monitor is already subscribed, nothing happens.subscribeEventProcessingMonitor
in interface EventProcessingMonitorSupport
monitor
- The monitor to subscribepublic void unsubscribeEventProcessingMonitor(EventProcessingMonitor monitor)
EventProcessingMonitorSupport
monitor
. If the monitor was not subscribed, or was already unsubscribed,
nothing happens.unsubscribeEventProcessingMonitor
in interface EventProcessingMonitorSupport
monitor
- The monitor to unsubscribeCopyright © 2010-2014. All Rights Reserved.