org.axonframework.eventstore.fs
Class FileSystemEventStore

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

public class FileSystemEventStore
extends Object
implements EventStore, SnapshotEventStore

Implementation of the EventStore that serializes objects using XStream and writes them to files to disk. Each aggregate is represented by a single file, where each event of that aggregate is a line in that file. Events are serialized to XML format, making them readable for both user and machine.

Use setBaseDir(org.springframework.core.io.Resource) to specify the directory where event files should be stored.

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

Since:
0.5
Author:
Allard Buijze

Constructor Summary
FileSystemEventStore()
          Basic initialization of the event store.
FileSystemEventStore(EventSerializer eventSerializer)
          Customized initialization of the event store.
 
Method Summary
 void appendEvents(String type, DomainEventStream eventsToStore)
          Append the events in the given stream to the event store.
 void appendSnapshotEvent(String type, DomainEvent snapshotEvent)
          Append the given snapshotEvent to the snapshot event log for the given type type.
 DomainEventStream readEvents(String type, AggregateIdentifier identifier)
          Read the events of the aggregate identified by the given type and identifier that allow the current aggregate state to be rebuilt.
 void setBaseDir(org.springframework.core.io.Resource baseDir)
          Sets the base directory where the event store will store all events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemEventStore

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


FileSystemEventStore

public FileSystemEventStore(EventSerializer eventSerializer)
Customized initialization of the event store. The actual serialization and deserialization is delegated to the provided eventSerializer .

Parameters:
eventSerializer - The serializer to serialize DomainEvents with
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,
                                    AggregateIdentifier identifier)
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
identifier - 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,
                                DomainEvent snapshotEvent)
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.

Note that the aggregate identifier and sequence number must be set on the DomainEvent. See DomainEvent.DomainEvent(long, org.axonframework.domain.AggregateIdentifier).

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.
See Also:
org.axonframework.domain.DomainEvent#DomainEvent(long, org.axonframework.domain.AggregateIdentifier))

setBaseDir

public void setBaseDir(org.springframework.core.io.Resource baseDir)
Sets the base directory where the event store will store all events.

Parameters:
baseDir - the location to store event files


Copyright © 2011. All Rights Reserved.