org.axonframework.eventstore.fs
Class FileSystemBufferedReaderDomainEventStream

java.lang.Object
  extended by org.axonframework.eventstore.fs.FileSystemBufferedReaderDomainEventStream
All Implemented Interfaces:
Closeable, DomainEventStream

public class FileSystemBufferedReaderDomainEventStream
extends Object
implements DomainEventStream, Closeable

DomainEventStream implementation that reads DomainEvents from the filesystem using an InputStream. Directly upcasts the events after reading using an UpcasterChain.

Since:
0.5
Author:
Allard Buijze, Frank Versnel

Constructor Summary
FileSystemBufferedReaderDomainEventStream(InputStream inputStream, Serializer serializer, UpcasterChain upcasterChain)
          Initialize a BufferedReaderDomainEventStream using the given inputStream and serializer.
 
Method Summary
 void close()
           
 boolean hasNext()
          Returns true if the stream has more events, meaning that a call to next() will not result in an exception.
 DomainEventMessage next()
          Returns the next events in the stream, if available.
 DomainEventMessage peek()
          Returns the next events in the stream, if available, without moving the pointer forward.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemBufferedReaderDomainEventStream

public FileSystemBufferedReaderDomainEventStream(InputStream inputStream,
                                                 Serializer serializer,
                                                 UpcasterChain upcasterChain)
Initialize a BufferedReaderDomainEventStream using the given inputStream and serializer. The inputStream must provide a serialized DomainEvent, prefixed with a UTF-8 encoded number indicating the number of bytes to read and a number representing the sequence number of the event. In between each number and the serialized DomainEvent, there must be at least a single whitespace character.

Example:
1234 The serialized domain event using 1234 bytes...

The reader will be closed when the last event has been read from it, or when an exception occurs while reading or deserializing an event.

Parameters:
inputStream - The inputStream providing serialized DomainEvents
serializer - The serializer to deserialize the DomainEvents
upcasterChain - used to upcast events directly after being read
Method Detail

hasNext

public boolean hasNext()
Description copied from interface: DomainEventStream
Returns true if the stream has more events, meaning that a call to next() will not result in an exception. If a call to this method returns false, there is no guarantee about the result of a consecutive call to next()

Specified by:
hasNext in interface DomainEventStream
Returns:
true if the stream contains more events.

next

public DomainEventMessage next()
Description copied from interface: DomainEventStream
Returns the next events in the stream, if available. Use hasNext() to obtain a guarantee about the availability of any next event. Each call to next() will forward the pointer to the next event in the stream.

If the pointer has reached the end of the stream, the behavior of this method is undefined. It could either return null, or throw an exception, depending on the actual implementation. Use DomainEventStream.hasNext() to confirm the existence of elements after the current pointer.

Specified by:
next in interface DomainEventStream
Returns:
the next event in the stream.

peek

public DomainEventMessage peek()
Description copied from interface: DomainEventStream
Returns the next events in the stream, if available, without moving the pointer forward. Hence, a call to DomainEventStream.next() will return the same event as a call to peek(). Use hasNext() to obtain a guarantee about the availability of any next event.

If the pointer has reached the end of the stream, the behavior of this method is undefined. It could either return null, or throw an exception, depending on the actual implementation. Use DomainEventStream.hasNext() to confirm the existence of elements after the current pointer.

Specified by:
peek in interface DomainEventStream
Returns:
the next event in the stream.

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2010-2016. All Rights Reserved.