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  DomainEvent createSnapshot(String typeIdentifier, 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, AggregateIdentifier 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, AggregateIdentifier 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.
 
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,
                             AggregateIdentifier 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,
                                         AggregateIdentifier 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 DomainEvent createSnapshot(String typeIdentifier,
                                              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
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.

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

setExecutor

public void setExecutor(Executor executor)
Sets the executor that should process actual snapshot taking. Defaults to a single threaded (asynchronous) executor.

Parameters:
executor - the executor to execute snapshotting tasks

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.

getExecutor

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

Returns:
the executor that executes snapshot taking tasks.


Copyright © 2011. All Rights Reserved.