Annotation 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.
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 ElementsModifier and TypeOptional ElementDescriptionintThe 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
FieldsModifier and TypeFieldDescriptionstatic final intSentinel value forafterEvents()indicating that no event-count threshold is configured at this level.static final StringSentinel value forafterSourcingTime()indicating that no sourcing-time threshold is configured at this level.
-
Field Details
-
USE_DEFAULT
static final int USE_DEFAULTSentinel value forafterEvents()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
Sentinel value forafterSourcingTime()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 afterEventsThe number of events after which a snapshot is triggered during sourcing. Set to a positive integer to enable. Set to0to explicitly disable this trigger. Defaults toUSE_DEFAULT, meaning the value is resolved from a higher-level annotation.- Returns:
- the event count threshold,
0to disable, orUSE_DEFAULTto inherit
- Default:
-2147483648
-
afterSourcingTime
String afterSourcingTimeThe maximum sourcing duration after which a snapshot is triggered, expressed as an ISO-8601 duration string (e.g.,"PT5S"for five seconds). Defaults toUSE_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_DURATIONto inherit
- Default:
"\u0000"
-