Class EventCountSnapshotTriggerDefinition

java.lang.Object
org.axonframework.eventsourcing.EventCountSnapshotTriggerDefinition
All Implemented Interfaces:
SnapshotTriggerDefinition

public class EventCountSnapshotTriggerDefinition extends Object implements SnapshotTriggerDefinition
Snapshotter trigger mechanism that counts the number of events to decide when to create a snapshot. A snapshot is triggered when the number of events applied on an aggregate exceeds the given threshold.

This number can exceed in two distinct scenarios:

  1. When initializing / event sourcing the aggregate in question.
  2. When new events are being applied by the aggregate.

If the definable threshold is met in situation one, the snapshot will be triggered regardless of the outcome of command handling. Thus also if command handling returns exceptionally. If the threshold is only reached once the aggregate has been fully initialized, than the snapshot will only be triggered if handling resolves successfully.

Since:
3.0
Author:
Allard Buijze
  • Constructor Details

    • EventCountSnapshotTriggerDefinition

      public EventCountSnapshotTriggerDefinition(Snapshotter snapshotter, int threshold)
      Initialized the SnapshotTriggerDefinition to threshold snapshots using the given snapshotter when threshold events have been applied to an Aggregate instance
      Parameters:
      snapshotter - the snapshotter to notify when a snapshot needs to be taken
      threshold - the number of events that will threshold the creation of a snapshot event
  • Method Details

    • prepareTrigger

      public SnapshotTrigger prepareTrigger(@Nonnull Class<?> aggregateType)
      Description copied from interface: SnapshotTriggerDefinition
      Prepares a new trigger for an aggregate with the given aggregateIdentifier and aggregateType. The trigger will be notified of each event applied on the aggregate, as well as the moment at which the aggregate state is fully initialized based on its historic events.

      It is highly recommended that the instances returned by this method are Serializable. Any resources that the trigger needs that are not serializable, can be reattached by implementing the SnapshotTriggerDefinition.reconfigure(Class, SnapshotTrigger) method. This method is invoked when a SnapshotTrigger has been deserialized.

      Specified by:
      prepareTrigger in interface SnapshotTriggerDefinition
      Parameters:
      aggregateType - The type of aggregate for which to create a trigger
      Returns:
      the trigger instance for an aggregate
    • reconfigure

      public SnapshotTrigger reconfigure(@Nonnull Class<?> aggregateType, @Nonnull SnapshotTrigger trigger)
      Description copied from interface: SnapshotTriggerDefinition
      Reconfigure the necessary infrastructure components in the given trigger instance, which may have been lost in the (de)serialization process.

      Since implementations of the SnapshotTrigger often rely on a Snapshotter which cannot be serialized, it may be necessary to inject these resourcs after deserialization of a trigger.

      Implementations returning a Serializable SnapshotTrigger (which is recommended), should implement this method if not all fields could be initialized base don serialized data.

      Specified by:
      reconfigure in interface SnapshotTriggerDefinition
      Parameters:
      aggregateType - The type of aggregate for which this trigger was created
      trigger - The trigger instance formerly created using SnapshotTriggerDefinition.prepareTrigger(Class)
      Returns:
      a fully (re)configured trigger instance, may be the same trigger instance.