Annotation Interface Snapshotting


@Target(TYPE) @Retention(RUNTIME) @Documented public @interface Snapshotting
Configures snapshotting behaviour for an event-sourced entity when using the annotation-based registration path (see EventSourcedEntityModule.autodetected(Class, Class)).

Place this annotation on an @EventSourcedEntity-annotated class to declare one or both snapshot trigger conditions:

  • afterEvents() — trigger a snapshot after a fixed number of events have been applied during sourcing.
  • afterSourcingTime() — trigger a snapshot when the total sourcing time for a load operation exceeds the given duration.
When both attributes are active, either condition independently triggers a snapshot (logical OR), matching the composition semantics of SnapshotPolicy.or(SnapshotPolicy).

Both attributes default to sentinel values (USE_DEFAULT and USE_DEFAULT_DURATION) meaning "not configured here". At least one attribute must resolve to a concrete value, either directly on the annotation or via a higher-level annotation on an enclosing class, package, or module. If no concrete value can be resolved, configuration fails with an AxonConfigurationException.

This makes it possible to define a shared snapshotting policy at the package or module level and let individual entities inherit it by simply placing @Snapshotting without further attributes:


 // package-info.java
 @Snapshotting(afterEvents = 50)
 package com.example.orders;
 

Example usage:

@EventSourcedEntity
@Snapshotting(afterEvents = 100)  // snapshot after every 100 events
public class BankAccount { ... }

@EventSourcedEntity
@Snapshotting(afterEvents = 100, afterSourcingTime = "PT5S")  // combined thresholds
public class OrderAggregate { ... }
Since:
5.1.1
Author:
John Hendrikx
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The number of events after which a snapshot is triggered during sourcing.
    The maximum sourcing duration after which a snapshot is triggered, expressed as an ISO-8601 duration string (e.g., "PT5S" for five seconds).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Sentinel value for afterEvents() indicating that no event-count threshold is configured at this level.
    static final String
    Sentinel value for afterSourcingTime() indicating that no sourcing-time threshold is configured at this level.
  • Field Details

    • USE_DEFAULT

      static final int USE_DEFAULT
      Sentinel value for afterEvents() indicating that no event-count threshold is configured at this level. The framework will look for a concrete value in enclosing classes, the package, or the module.
      See Also:
    • USE_DEFAULT_DURATION

      static final String USE_DEFAULT_DURATION
      Sentinel value for afterSourcingTime() indicating that no sourcing-time threshold is configured at this level. The framework will look for a concrete value in enclosing classes, the package, or the module.
      See Also:
  • Element Details

    • afterEvents

      int afterEvents
      The number of events after which a snapshot is triggered during sourcing. Set to a positive integer to enable. Set to 0 to explicitly disable this trigger. Defaults to USE_DEFAULT, meaning the value is resolved from a higher-level annotation.
      Returns:
      the event count threshold, 0 to disable, or USE_DEFAULT to inherit
      Default:
      -2147483648
    • afterSourcingTime

      String afterSourcingTime
      The maximum sourcing duration after which a snapshot is triggered, expressed as an ISO-8601 duration string (e.g., "PT5S" for five seconds). Defaults to USE_DEFAULT_DURATION, meaning the value is resolved from a higher-level annotation.
      Returns:
      the sourcing-time threshold as an ISO-8601 duration, or USE_DEFAULT_DURATION to inherit
      Default:
      "\u0000"