org.axonframework.eventstore.fs
Class SimpleEventFileResolver

java.lang.Object
  extended by org.axonframework.eventstore.fs.SimpleEventFileResolver
All Implemented Interfaces:
EventFileResolver

public class SimpleEventFileResolver
extends Object
implements EventFileResolver

Very straightforward implementation of the EventFileResolver that stores files in a directory structure underneath a given base directory. Events of a single aggregate are appended to a pair of files, one for regular events and one for snapshot events. Directories are used to separate files for different aggregate types.

Since:
0.5
Author:
Allard Buijze

Field Summary
static String FILE_EXTENSION_EVENTS
          Describes the file extension used for files containing domain events.
static String FILE_EXTENSION_SNAPSHOTS
          Describes the file extension used for files containing snapshot events.
 
Constructor Summary
SimpleEventFileResolver(File baseDir)
          Initialize the SimpleEventFileResolver with the given baseDir.
 
Method Summary
 boolean eventFileExists(String type, Object identifier)
          Indicates whether there is a file containing (regular) events for the given aggregateIdentifier of given type.
 InputStream openEventFileForReading(String type, Object identifier)
          Provides an input stream to the (regular) events file for the aggregate with the given aggregateIdentifier and of given type.
 OutputStream openEventFileForWriting(String type, Object aggregateIdentifier)
          Provides an output stream to the (regular) events file for the aggregate with the given aggregateIdentifier and of given type.
 InputStream openSnapshotFileForReading(String type, Object identifier)
          Provides an input stream to the snapshot events file for the aggregate with the given aggregateIdentifier and of given type.
 OutputStream openSnapshotFileForWriting(String type, Object aggregateIdentifier)
          Provides an output stream to the snapshot events file for the aggregate with the given aggregateIdentifier and of given type.
 boolean snapshotFileExists(String type, Object identifier)
          Indicates whether there is a file containing snapshot events for the given aggregateIdentifier of given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_EXTENSION_EVENTS

public static final String FILE_EXTENSION_EVENTS
Describes the file extension used for files containing domain events.

See Also:
Constant Field Values

FILE_EXTENSION_SNAPSHOTS

public static final String FILE_EXTENSION_SNAPSHOTS
Describes the file extension used for files containing snapshot events.

See Also:
Constant Field Values
Constructor Detail

SimpleEventFileResolver

public SimpleEventFileResolver(File baseDir)
Initialize the SimpleEventFileResolver with the given baseDir.

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

Parameters:
baseDir - The directory where event files are stored.
Method Detail

openEventFileForWriting

public OutputStream openEventFileForWriting(String type,
                                            Object aggregateIdentifier)
                                     throws IOException
Description copied from interface: EventFileResolver
Provides an output stream to the (regular) events file for the aggregate with the given aggregateIdentifier and of given type. Written bytes are appended to already existing information.

The caller of this method is responsible for closing the output stream when all data has been written to it.

Specified by:
openEventFileForWriting in interface EventFileResolver
Parameters:
type - The type of aggregate to open the stream for
aggregateIdentifier - the identifier of the aggregate
Returns:
an OutputStream that appends to the event log of of the given aggregate
Throws:
IOException - when an error occurs while opening a file

openSnapshotFileForWriting

public OutputStream openSnapshotFileForWriting(String type,
                                               Object aggregateIdentifier)
                                        throws IOException
Description copied from interface: EventFileResolver
Provides an output stream to the snapshot events file for the aggregate with the given aggregateIdentifier and of given type. Written bytes are appended to already existing information.

The caller of this method is responsible for closing the output stream when all data has been written to it.

Specified by:
openSnapshotFileForWriting in interface EventFileResolver
Parameters:
type - The type of aggregate to open the stream for
aggregateIdentifier - the identifier of the aggregate
Returns:
an OutputStream that appends to the snapshot event log of of the given aggregate
Throws:
IOException - when an error occurs while opening a file

openEventFileForReading

public InputStream openEventFileForReading(String type,
                                           Object identifier)
                                    throws IOException
Description copied from interface: EventFileResolver
Provides an input stream to the (regular) events file for the aggregate with the given aggregateIdentifier and of given type.

The caller of this method is responsible for closing the input stream when done reading from it.

Specified by:
openEventFileForReading in interface EventFileResolver
Parameters:
type - The type of aggregate to open the stream for
identifier - the identifier of the aggregate
Returns:
an InputStream that reads from the event log of of the given aggregate
Throws:
IOException - when an error occurs while opening a file

openSnapshotFileForReading

public InputStream openSnapshotFileForReading(String type,
                                              Object identifier)
                                       throws IOException
Description copied from interface: EventFileResolver
Provides an input stream to the snapshot events file for the aggregate with the given aggregateIdentifier and of given type.

The caller of this method is responsible for closing the input stream when done reading from it.

Specified by:
openSnapshotFileForReading in interface EventFileResolver
Parameters:
type - The type of aggregate to open the stream for
identifier - the identifier of the aggregate
Returns:
an InputStream that reads from the snapshot event log of of the given aggregate
Throws:
IOException - when an error occurs while opening a file

eventFileExists

public boolean eventFileExists(String type,
                               Object identifier)
                        throws IOException
Description copied from interface: EventFileResolver
Indicates whether there is a file containing (regular) events for the given aggregateIdentifier of given type.

Specified by:
eventFileExists in interface EventFileResolver
Parameters:
type - The type of aggregate
identifier - the identifier of the aggregate
Returns:
true if an event log exists for the aggregate, false otherwise.
Throws:
IOException - when an error occurs while reading from the FileSystem. The existence of the event file is undetermined.

snapshotFileExists

public boolean snapshotFileExists(String type,
                                  Object identifier)
                           throws IOException
Description copied from interface: EventFileResolver
Indicates whether there is a file containing snapshot events for the given aggregateIdentifier of given type.

Specified by:
snapshotFileExists in interface EventFileResolver
Parameters:
type - The type of aggregate
identifier - the identifier of the aggregate
Returns:
true if a snapshot event log exists for the aggregate, false otherwise.
Throws:
IOException - when an error occurs while reading from the FileSystem. The existence of the event file is undetermined.


Copyright © 2010-2016. All Rights Reserved.