org.axonframework.eventhandling.replay
Class ReplayingCluster

java.lang.Object
  extended by org.axonframework.eventhandling.replay.ReplayingCluster
All Implemented Interfaces:
Cluster, EventProcessingMonitorSupport

public class ReplayingCluster
extends Object
implements Cluster

Cluster implementation that wraps another Cluster, adding the capability to replay events from an Event Store. All events are forwarded for handling to a delegate cluster. When in replay mode, incoming events are forwarded to an 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.

Since:
2.0
Author:
Allard Buijze

Field Summary
static String AFTER_REPLAY_TIMEOUT
          The key to use in Cluster MetaData that indicates how long the replaying cluster should wait for all events to be processed, before invoking the afterReplay on all methods.
 
Constructor Summary
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.
 
Method Summary
 long getAfterReplayTimeout()
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AFTER_REPLAY_TIMEOUT

public static final String AFTER_REPLAY_TIMEOUT
The key to use in Cluster MetaData that indicates how long the replaying cluster should wait for all events to be processed, before invoking the afterReplay on all methods. Defaults to 5 seconds.

See Also:
Constant Field Values
Constructor Detail

ReplayingCluster

public 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. 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.

Parameters:
delegate - The cluster to add replaying capability to
eventStore - The event store providing access to events to replay
transactionManager - The transaction manager providing the transaction for the replay process
commitThreshold - 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 mode
Method Detail

newCriteriaBuilder

public CriteriaBuilder newCriteriaBuilder()
Returns a CriteriaBuilder that allows the construction of criteria for this EventStore implementation

Returns:
a builder to create Criteria for this Event Store.
See Also:
EventStoreManagement.newCriteriaBuilder()

startReplay

public void startReplay()
Starts a replay process on the current thread. This method will return once the replay process is finished.

Throws:
ReplayFailedException - when an exception occurred during the replay process

startReplay

public void startReplay(Criteria criteria)
Start a replay process on the current thread, only reading events matching the given criteria. This method will return once the replay process is finished.

Parameters:
criteria - The criteria defining the events to reply
Throws:
ReplayFailedException - when an exception occurred during the replay process

startReplay

public Future<Void> startReplay(Executor executor)
Starts a replay process using the given executor. The replay process itself uses a single thread.

Parameters:
executor - The executor to execute the replay process
Returns:
a Future that allows the calling thread to track progress.

startReplay

public Future<Void> startReplay(Executor executor,
                                Criteria criteria)
Starts a replay process using the given executor, only reading events matching the given criteria. The replay process itself uses a single thread.

Parameters:
executor - The executor to execute the replay process
criteria - The criteria defining the events to reply
Returns:
a Future that allows the calling thread to track progress.
Throws:
ReplayFailedException - when an exception occurred during the replay process

isInReplayMode

public boolean isInReplayMode()
Indicates whether this cluster is in replay mode. While in replay mode, EventMessages published to this cluster are forwarded to the IncomingMessageHandler.

Returns:
true if this cluster is in replay mode, false otherwise.

getName

public String getName()
Description copied from interface: Cluster
Returns the name of this cluster. This name is used to detect distributed instances of the same cluster. Multiple instances referring to the same logical cluster (on different JVM's) must have the same name.

Specified by:
getName in interface Cluster
Returns:
the name of this cluster

publish

public void publish(EventMessage... events)
Description copied from interface: Cluster
Publishes the given Events to the members of this cluster.

Implementations may do this synchronously or asynchronously. Although 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.

Specified by:
publish in interface Cluster
Parameters:
events - The Events to publish in the cluster

subscribe

public void subscribe(EventListener eventListener)
Subscribe the given 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.

Specified by:
subscribe in interface Cluster
Parameters:
eventListener - the Event Listener instance to subscribe
See Also:
isInReplayMode()

unsubscribe

public void unsubscribe(EventListener eventListener)
Unsubscribes the given 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.

Specified by:
unsubscribe in interface Cluster
Parameters:
eventListener - the Event Listener instance to unsubscribe
See Also:
isInReplayMode()

getMembers

public Set<EventListener> getMembers()
Description copied from interface: Cluster
Returns a read-only view on the members in the cluster. This view may be updated by the Cluster when members subscribe or unsubscribe. Cluster implementations may also return the view representing the state at the moment this method is invoked.

Specified by:
getMembers in interface Cluster
Returns:
a view of the members of this cluster

getMetaData

public ClusterMetaData getMetaData()
Description copied from interface: Cluster
Returns the MetaData of this Cluster.

Specified by:
getMetaData in interface Cluster
Returns:
the MetaData of this Cluster

subscribeEventProcessingMonitor

public void subscribeEventProcessingMonitor(EventProcessingMonitor monitor)
Description copied from interface: EventProcessingMonitorSupport
Subscribes the given monitor. If the monitor is already subscribed, nothing happens.

Specified by:
subscribeEventProcessingMonitor in interface EventProcessingMonitorSupport
Parameters:
monitor - The monitor to subscribe

unsubscribeEventProcessingMonitor

public void unsubscribeEventProcessingMonitor(EventProcessingMonitor monitor)
Description copied from interface: EventProcessingMonitorSupport
Unsubscribed the given monitor. If the monitor was not subscribed, or was already unsubscribed, nothing happens.

Specified by:
unsubscribeEventProcessingMonitor in interface EventProcessingMonitorSupport
Parameters:
monitor - The monitor to unsubscribe

getAfterReplayTimeout

public long getAfterReplayTimeout()


Copyright © 2010-2016. All Rights Reserved.