org.axonframework.eventstore.fs
Class FileSystemEventStore

java.lang.Object
  extended by org.axonframework.eventstore.fs.FileSystemEventStore
All Implemented Interfaces:
EventStore, SnapshotEventStore, UpcasterAware

public class FileSystemEventStore
extends Object
implements EventStore, SnapshotEventStore, UpcasterAware

Implementation of the EventStore that serializes objects (by default using XStream) and writes them to files to disk. Each aggregate is represented by a single file.

Use EventFileResolver to specify the directory where event files should be stored and written to.

Note that the resource supplied must point to a folder and should contain a trailing slash. See org.springframework.core.io.FileSystemResource#FileSystemResource(String).

Since:
0.5
Author:
Allard Buijze, Frank Versnel

Constructor Summary
FileSystemEventStore(EventFileResolver eventFileResolver)
          Basic initialization of the event store.
FileSystemEventStore(Serializer serializer, EventFileResolver eventFileResolver)
          Initialize the FileSystemEventStore using the given serializer.
 
Method Summary
 void appendEvents(String type, DomainEventStream eventsToStore)
          Append the events in the given stream to the event store.
 void appendSnapshotEvent(String type, DomainEventMessage snapshotEvent)
          Append the given snapshotEvent to the snapshot event log for the given type type.
 DomainEventStream readEvents(String type, Object aggregateIdentifier)
          Read the events of the aggregate identified by the given type and identifier that allow the current aggregate state to be rebuilt.
 void setUpcasterChain(UpcasterChain upcasterChain)
          Sets the UpcasterChain which allow older revisions of serialized objects to be deserialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemEventStore

public FileSystemEventStore(EventFileResolver eventFileResolver)
Basic initialization of the event store. The actual serialization and deserialization is delegated to a XStreamSerializer

Parameters:
eventFileResolver - The EventFileResolver providing access to event files

FileSystemEventStore

public FileSystemEventStore(Serializer serializer,
                            EventFileResolver eventFileResolver)
Initialize the FileSystemEventStore using the given serializer. The serializer must be capable of serializing the payload and meta data of Event Messages.

Note: the SerializedType of Message Meta Data is not stored. Upon retrieval, it is set to the default value (name = "org.axonframework.domain.MetaData", revision = null). See SerializedMetaData.isSerializedMetaData(org.axonframework.serializer.SerializedObject)

Parameters:
serializer - The serializer capable of serializing (at least) DomainEvents
eventFileResolver - The EventFileResolver providing access to event files
Method Detail

appendEvents

public void appendEvents(String type,
                         DomainEventStream eventsToStore)
Append the events in the given stream to the event store.

This implementation writes events to an event log on the file system. It uses a directory per type of aggregate, containing 1 file per aggregate.

Specified by:
appendEvents in interface EventStore
Parameters:
type - The type descriptor of the object to store
eventsToStore - The event stream containing the events to store

readEvents

public DomainEventStream readEvents(String type,
                                    Object aggregateIdentifier)
Description copied from interface: EventStore
Read the events of the aggregate identified by the given type and identifier that allow the current aggregate state to be rebuilt. Implementations may omit or replace events (e.g. by using snapshot events) from the stream for performance purposes.

Specified by:
readEvents in interface EventStore
Parameters:
type - The type descriptor of the object to retrieve
aggregateIdentifier - The unique aggregate identifier of the events to load
Returns:
an event stream containing the events of the aggregate

appendSnapshotEvent

public void appendSnapshotEvent(String type,
                                DomainEventMessage snapshotEvent)
                         throws EventStoreException
Append the given snapshotEvent to the snapshot event log for the given type type. The sequence number of the snapshotEvent must be equal to the sequence number of the last regular domain event that is included in the snapshot.

Implementations may choose to prune snapshots upon appending a new snapshot, in order to minimize storage space.

Specified by:
appendSnapshotEvent in interface SnapshotEventStore
Parameters:
type - The type of aggregate the event belongs to
snapshotEvent - The event summarizing one or more domain events for a specific aggregate.
Throws:
EventStoreException - when an error occurs while reading or writing to the event logs.

setUpcasterChain

public void setUpcasterChain(UpcasterChain upcasterChain)
Description copied from interface: UpcasterAware
Sets the UpcasterChain which allow older revisions of serialized objects to be deserialized.

Specified by:
setUpcasterChain in interface UpcasterAware
Parameters:
upcasterChain - the upcaster chain providing the upcasting capabilities


Copyright © 2010-2016. All Rights Reserved.