public class EmbeddedEventStore extends AbstractEventStore
EventStore
that stores and fetches events using an EventStorageEngine
. If
supported by its storage engine the embedded event store provides event tracking and replaying capabilities.
The event store can be tracked by multiple event processors simultaneously. To prevent that each event processor needs to read from the storage engine individually the embedded event store contains a cache of the most recent events. This cache is shared between the streams of various event processors. So, assuming an event processor processes events fast enough and is not far behind the head of the event log it will not need a private connection to the underlying data store. The size of the cache (in number of events) is configurable.
The embedded event store automatically fetches new events from the store if there is at least one registered tracking event processor present. It will do so after new events are committed to the store, as well as periodically as events may have been committed by other nodes or applications. This periodic fetch delay is configurable.
Constructor and Description |
---|
EmbeddedEventStore(EventStorageEngine storageEngine)
Initializes an
EmbeddedEventStore with given storageEngine and default settings. |
EmbeddedEventStore(EventStorageEngine storageEngine,
MessageMonitor<? super EventMessage<?>> monitor)
|
EmbeddedEventStore(EventStorageEngine storageEngine,
MessageMonitor<? super EventMessage<?>> monitor,
int cachedEvents,
long fetchDelay,
long cleanupDelay,
TimeUnit timeUnit)
|
Modifier and Type | Method and Description |
---|---|
protected void |
afterCommit(List<? extends EventMessage<?>> events)
Process given
events after the Unit of Work has been committed. |
TrackingEventStream |
openStream(TrackingToken trackingToken)
Open an event stream containing all events since given tracking token.
|
void |
shutDown()
Method to invoke when the application shuts down.
|
prepareCommit, readEvents, readEvents, stagedDomainEventMessages, storageEngine, storeSnapshot
commit, intercept, publish, queuedMessages, registerDispatchInterceptor, subscribe
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
publish, publish, registerDispatchInterceptor
subscribe
public EmbeddedEventStore(EventStorageEngine storageEngine)
EmbeddedEventStore
with given storageEngine
and default settings.storageEngine
- the storage engine to usepublic EmbeddedEventStore(EventStorageEngine storageEngine, MessageMonitor<? super EventMessage<?>> monitor)
storageEngine
- the storage engine to usemonitor
- the metrics monitor that tracks how many events are ingested by the event storepublic EmbeddedEventStore(EventStorageEngine storageEngine, MessageMonitor<? super EventMessage<?>> monitor, int cachedEvents, long fetchDelay, long cleanupDelay, TimeUnit timeUnit)
storageEngine
- the storage engine to usemonitor
- the metrics monitor that tracks how many events are ingested by the event storecachedEvents
- the maximum number of events in the cache that is shared between the streams of tracking
event processorsfetchDelay
- the time to wait before fetching new events from the backing storage engine while tracking
after a previous stream was fetched and read. Note that this only applies to situations in
which no events from the current application have meanwhile been committed. If the current
application commits events then those events are fetched without delay.cleanupDelay
- the delay between two clean ups of lagging event processors. An event processor is lagging
behind and removed from the set of processors that track cached events if the oldest event
in the cache is newer than the last processed event of the event processor. Once removed the
processor will be independently fetching directly from the event storage engine until it has
caught up again. Event processors will not notice this change during tracking (i.e. the
stream is not closed when an event processor falls behind and is removed).timeUnit
- time unit for fetch and clean up delay@PreDestroy public void shutDown()
protected void afterCommit(List<? extends EventMessage<?>> events)
AbstractEventBus
events
after the Unit of Work has been committed. The default implementation does
nothing.afterCommit
in class AbstractEventBus
events
- Events to be published by this Event Buspublic TrackingEventStream openStream(TrackingToken trackingToken)
EventBus
trackingToken
of null
to open a
stream containing all available events. Note that the returned stream is infinite, so beware of applying
terminal operations to the returned stream.
In case the event bus cannot open a stream for a given tracking token, for instance because the event bus does
not persist or cache events, the event bus will throw an UnsupportedOperationException
.
trackingToken
- object describing the previous position in the stream or null
to create a
stream of all eventsTrackingEventStream
with events since the given trackingTokenCopyright © 2010–2017. All rights reserved.