org.axonframework.eventsourcing
Class AbstractSnapshotter

java.lang.Object
  extended by org.axonframework.eventsourcing.AbstractSnapshotter
All Implemented Interfaces:
Snapshotter
Direct Known Subclasses:
AggregateSnapshotter

public abstract class AbstractSnapshotter
extends Object
implements Snapshotter

Abstract implementation of the Snapshotter that uses a task executor to creates snapshots. Actual snapshot creation logic should be provided by a subclass.

By default, this implementations uses a DirectExecutor to process snapshot taking tasks. In production environments, it is recommended to use asynchronous executors instead.

Since:
0.6
Author:
Allard Buijze

Constructor Summary
AbstractSnapshotter()
           
 
Method Summary
protected abstract  DomainEventMessage createSnapshot(String typeIdentifier, Object aggregateIdentifier, DomainEventStream eventStream)
          Creates a snapshot event for an aggregate of the given typeIdentifier of which passed events are available in the given eventStream.
protected  Runnable createSnapshotterTask(String typeIdentifier, Object aggregateIdentifier)
          Creates an instance of a task that contains the actual snapshot creation logic.
protected  SnapshotEventStore getEventStore()
          Returns the event store this snapshotter uses to load domain events and store snapshot events.
protected  Executor getExecutor()
          Returns the executor that executes snapshot taking tasks.
 void scheduleSnapshot(String typeIdentifier, Object aggregateIdentifier)
          Schedules snapshot taking for an aggregate with given typeIdentifier and aggregateIdentifier.
 void setEventStore(SnapshotEventStore eventStore)
          Sets the event store where the snapshotter can load domain events and store its snapshot events.
 void setExecutor(Executor executor)
          Sets the executor that should process actual snapshot taking.
 void setTxManager(TransactionManager<?> transactionManager)
          Sets the transactionManager that wraps the snapshot creation in a transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSnapshotter

public AbstractSnapshotter()
Method Detail

scheduleSnapshot

public void scheduleSnapshot(String typeIdentifier,
                             Object aggregateIdentifier)
Description copied from interface: Snapshotter
Schedules snapshot taking for an aggregate with given typeIdentifier and aggregateIdentifier. The implementation may choose to process this call synchronously (i.e. in the caller's thread), asynchronously, or ignore the call altogether.

Specified by:
scheduleSnapshot in interface Snapshotter
Parameters:
typeIdentifier - the type of the aggregate to take the snapshot for
aggregateIdentifier - The identifier of the aggregate to take the snapshot for

createSnapshotterTask

protected Runnable createSnapshotterTask(String typeIdentifier,
                                         Object aggregateIdentifier)
Creates an instance of a task that contains the actual snapshot creation logic.

Parameters:
typeIdentifier - The type of the aggregate to create a snapshot for
aggregateIdentifier - The identifier of the aggregate to create a snapshot for
Returns:
the task containing snapshot creation logic

createSnapshot

protected abstract DomainEventMessage createSnapshot(String typeIdentifier,
                                                     Object aggregateIdentifier,
                                                     DomainEventStream eventStream)
Creates a snapshot event for an aggregate of the given typeIdentifier of which passed events are available in the given eventStream. May return null to indicate a snapshot event is not necessary or appropriate for the given event stream.

Parameters:
typeIdentifier - The aggregate's type identifier
aggregateIdentifier - The identifier of the aggregate to create a snapshot for
eventStream - The event stream containing the aggregate's past events
Returns:
the snapshot event for the given events, or null if none should be stored.

setTxManager

public void setTxManager(TransactionManager<?> transactionManager)
Sets the transactionManager that wraps the snapshot creation in a transaction. By default, no transactions are created.

Parameters:
transactionManager - the transactionManager to create transactions with

getEventStore

protected SnapshotEventStore getEventStore()
Returns the event store this snapshotter uses to load domain events and store snapshot events.

Returns:
the event store this snapshotter uses to load domain events and store snapshot events.

setEventStore

public void setEventStore(SnapshotEventStore eventStore)
Sets the event store where the snapshotter can load domain events and store its snapshot events.

Parameters:
eventStore - the event store to use

getExecutor

protected Executor getExecutor()
Returns the executor that executes snapshot taking tasks.

Returns:
the executor that executes snapshot taking tasks.

setExecutor

public void setExecutor(Executor executor)
Sets the executor that should process actual snapshot taking. Defaults to an instance that runs all actions in the calling thread (i.e. synchronous execution).

Parameters:
executor - the executor to execute snapshotting tasks


Copyright © 2010-2016. All Rights Reserved.