org.axonframework.eventhandling.replay
Class ReplayingCluster

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

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

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
 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.
 void publish(EventMessage... events)
          Publishes the given Events to the members of this cluster.
 void startReplay()
          Starts a replay process on the current thread.
 Future<Void> startReplay(Executor executor)
          Starts a replay process using the given executor.
 void subscribe(EventListener eventListener)
          Subscribe the given eventListener to this cluster.
 void unsubscribe(EventListener eventListener)
          Unsubscribes the given eventListener from this cluster.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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

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


Copyright © 2010-2012. All Rights Reserved.