org.axonframework.eventsourcing
Class EventCountSnapshotterTrigger

java.lang.Object
  extended by org.axonframework.eventsourcing.EventCountSnapshotterTrigger
All Implemented Interfaces:
EventStreamDecorator, SnapshotterTrigger

public class EventCountSnapshotterTrigger
extends Object
implements SnapshotterTrigger

Snapshotter trigger mechanism that counts the number of events to decide when to create a snapshot. This implementation acts as a proxy towards the actual event store, and keeps track of the number of "unsnapshotted" events for each aggregate. This means repositories should be configured to use an instance of this class instead of the actual event store.

Since:
0.6
Author:
Allard Buijze

Constructor Summary
EventCountSnapshotterTrigger()
           
 
Method Summary
 DomainEventStream decorateForAppend(String aggregateType, EventSourcedAggregateRoot aggregate, DomainEventStream eventStream)
          Called when an event stream is appended to the event store.
 DomainEventStream decorateForRead(String aggregateType, Object aggregateIdentifier, DomainEventStream eventStream)
          Called when an event stream is read from the event store.
 void setAggregateCache(Cache cache)
          Sets the Cache instance used be Caching repositories.
 void setAggregateCaches(List<Cache> caches)
          Sets the Cache instances used be Caching repositories.
 void setClearCountersAfterAppend(boolean clearCountersAfterAppend)
          Indicates whether to maintain counters for aggregates after appending events to the event store for these aggregates.
 void setSnapshotter(Snapshotter snapshotter)
          Sets the snapshotter to notify when a snapshot needs to be taken.
 void setTrigger(int trigger)
          Sets the number of events that will trigger the creation of a snapshot events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventCountSnapshotterTrigger

public EventCountSnapshotterTrigger()
Method Detail

decorateForRead

public DomainEventStream decorateForRead(String aggregateType,
                                         Object aggregateIdentifier,
                                         DomainEventStream eventStream)
Description copied from interface: EventStreamDecorator
Called when an event stream is read from the event store.

Note that a stream is read-once, similar to InputStream. If you read from the stream, make sure to store the read events and pass them to the chain. Usually, it is best to decorate the given eventStream and pass that to the chain.

Specified by:
decorateForRead in interface EventStreamDecorator
Parameters:
aggregateType - The type of aggregate events are being read for
aggregateIdentifier - The identifier of the aggregate events are loaded for
eventStream - The eventStream containing the events to append to the event store
Returns:
the decorated event stream

decorateForAppend

public DomainEventStream decorateForAppend(String aggregateType,
                                           EventSourcedAggregateRoot aggregate,
                                           DomainEventStream eventStream)
Description copied from interface: EventStreamDecorator
Called when an event stream is appended to the event store.

Note that a stream is read-once, similar to InputStream. If you read from the stream, make sure to store the read events and pass them to the chain. Usually, it is best to decorate the given eventStream and pass that to the chain.

Specified by:
decorateForAppend in interface EventStreamDecorator
Parameters:
aggregateType - The type of aggregate events are being appended for
aggregate - The aggregate for which the events are being stored
eventStream - The eventStream containing the events to append to the event store
Returns:
the decorated event stream

setSnapshotter

public void setSnapshotter(Snapshotter snapshotter)
Sets the snapshotter to notify when a snapshot needs to be taken.

Parameters:
snapshotter - the snapshotter to notify

setTrigger

public void setTrigger(int trigger)
Sets the number of events that will trigger the creation of a snapshot events. Defaults to 50.

This means that a snapshot is created as soon as loading an aggregate would require reading in more than 50 events.

Parameters:
trigger - The default trigger value.

setClearCountersAfterAppend

public void setClearCountersAfterAppend(boolean clearCountersAfterAppend)
Indicates whether to maintain counters for aggregates after appending events to the event store for these aggregates. Defaults to true.

By setting this value to false, event counters are kept in memory. This is particularly useful when repositories use caches, preventing events from being loaded. Consider registering the Caches use using setAggregateCache(org.axonframework.cache.Cache) or setAggregateCaches(java.util.List)

Parameters:
clearCountersAfterAppend - indicator whether to clear counters after appending events

setAggregateCache

public void setAggregateCache(Cache cache)
Sets the Cache instance used be Caching repositories. By registering them to the snapshotter trigger, it can optimize memory usage by clearing counters held for aggregates that are contained in caches. When an aggregate is evicted or deleted from the cache, its event counter is removed from the trigger.

Use the setAggregateCaches(java.util.List) method if you have configured different caches for different repositories.

Using this method will automatically set setClearCountersAfterAppend(boolean) to false.

Parameters:
cache - The cache used by caching repositories
See Also:
setAggregateCaches(java.util.List)

setAggregateCaches

public void setAggregateCaches(List<Cache> caches)
Sets the Cache instances used be Caching repositories. By registering them to the snapshotter trigger, it can optimize memory usage by clearing counters held for aggregates that are contained in caches. When an aggregate is evicted or deleted from the cache, its event counter is removed from the trigger.

Parameters:
caches - The caches used by caching repositories


Copyright © 2010-2016. All Rights Reserved.