Class AggregateLoadTimeSnapshotTriggerDefinition
- All Implemented Interfaces:
SnapshotTriggerDefinition
loadTimeMillisThreshold
in milliseconds.
This threshold can be exceeded in two distinct scenarios:
- When initializing / event sourcing the aggregate in question.
- When new events are being applied by the aggregate.
If the definable loadTimeMillisThreshold 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 loadTimeMillisThreshold is only reached
once the aggregate has been fully initialized, than the snapshot will only be triggered if handling resolves
successfully.
- Since:
- 4.4.4
- Author:
- Yvonne Ceelie
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAggregateLoadTimeSnapshotTriggerDefinition(Snapshotter snapshotter, long loadTimeMillisThreshold) Initialize aSnapshotTriggerDefinitionto trigger snapshot creation using the givensnapshotterwhen loading the aggregate instance takes longer than the givenloadTimeMillisThreshold. -
Method Summary
Modifier and TypeMethodDescriptionprepareTrigger(Class<?> aggregateType) Prepares a new trigger for an aggregate with the givenaggregateIdentifierandaggregateType.reconfigure(Class<?> aggregateType, SnapshotTrigger trigger) Reconfigure the necessary infrastructure components in the giventrigger instance, which may have been lost in the (de)serialization process.
-
Field Details
-
clock
-
-
Constructor Details
-
AggregateLoadTimeSnapshotTriggerDefinition
public AggregateLoadTimeSnapshotTriggerDefinition(Snapshotter snapshotter, long loadTimeMillisThreshold) Initialize aSnapshotTriggerDefinitionto trigger snapshot creation using the givensnapshotterwhen loading the aggregate instance takes longer than the givenloadTimeMillisThreshold.- Parameters:
snapshotter- the snapshotter to notify when a snapshot needs to be takenloadTimeMillisThreshold- the maximum time that loading an aggregate may take
-
-
Method Details
-
prepareTrigger
Description copied from interface:SnapshotTriggerDefinitionPrepares a new trigger for an aggregate with the givenaggregateIdentifierandaggregateType. 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 theSnapshotTriggerDefinition.reconfigure(Class, SnapshotTrigger)method. This method is invoked when a SnapshotTrigger has been deserialized.- Specified by:
prepareTriggerin interfaceSnapshotTriggerDefinition- 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:SnapshotTriggerDefinitionReconfigure the necessary infrastructure components in the giventrigger instance, which may have been lost in the (de)serialization process.Since implementations of the
SnapshotTriggeroften rely on aSnapshotterwhich 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:
reconfigurein interfaceSnapshotTriggerDefinition- Parameters:
aggregateType- The type of aggregate for which this trigger was createdtrigger- The trigger instance formerly created usingSnapshotTriggerDefinition.prepareTrigger(Class)- Returns:
- a fully (re)configured trigger instance, may be the same
triggerinstance.
-