Interface SnapshotTriggerDefinition

All Known Implementing Classes:
AggregateLoadTimeSnapshotTriggerDefinition, EventCountSnapshotTriggerDefinition, NoSnapshotTriggerDefinition

public interface SnapshotTriggerDefinition
Interface describing the mechanism for triggering Snapshots. The SnapshotTriggerDefinition creates specific trigger instances for each Aggregate. The lifecycle of these triggers is attached to the lifecycle of the aggregate itself. This means the trigger is cached if the aggregate is, and it is disposed together with the aggregate.

This means aggregate-specific state should be kept in the SnapshotTrigger instances, and not in the SnapshotTriggerDefinition

Since:
3.0
Author:
Allard Buijze
  • Method Summary

    Modifier and Type
    Method
    Description
    prepareTrigger(Class<?> aggregateType)
    Prepares a new trigger for an aggregate with the given aggregateIdentifier and aggregateType.
    reconfigure(Class<?> aggregateType, SnapshotTrigger trigger)
    Reconfigure the necessary infrastructure components in the given trigger instance, which may have been lost in the (de)serialization process.
  • Method Details

    • prepareTrigger

      SnapshotTrigger prepareTrigger(@Nonnull Class<?> aggregateType)
      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 reconfigure(Class, SnapshotTrigger) method. This method is invoked when a SnapshotTrigger has been deserialized.

      Parameters:
      aggregateType - The type of aggregate for which to create a trigger
      Returns:
      the trigger instance for an aggregate
    • reconfigure

      default SnapshotTrigger reconfigure(@Nonnull Class<?> aggregateType, @Nonnull SnapshotTrigger trigger)
      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.

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