public class AggregateLoadTimeSnapshotTriggerDefinition extends Object implements SnapshotTriggerDefinition
loadTimeMillisThreshold
in milliseconds.
This threshold can be exceeded in two distinct scenarios:
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.
Constructor and Description |
---|
AggregateLoadTimeSnapshotTriggerDefinition(Snapshotter snapshotter,
long loadTimeMillisThreshold)
Initialize a
SnapshotTriggerDefinition to trigger snapshot creation using the given snapshotter
when loading the aggregate instance takes longer than the given loadTimeMillisThreshold . |
Modifier and Type | Method and Description |
---|---|
SnapshotTrigger |
prepareTrigger(Class<?> aggregateType)
Prepares a new trigger for an aggregate with the given
aggregateIdentifier and aggregateType . |
SnapshotTrigger |
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. |
public static Clock clock
public AggregateLoadTimeSnapshotTriggerDefinition(Snapshotter snapshotter, long loadTimeMillisThreshold)
SnapshotTriggerDefinition
to trigger snapshot creation using the given snapshotter
when loading the aggregate instance takes longer than the given loadTimeMillisThreshold
.snapshotter
- the snapshotter to notify when a snapshot needs to be takenloadTimeMillisThreshold
- the maximum time that loading an aggregate may takepublic SnapshotTrigger prepareTrigger(@Nonnull Class<?> aggregateType)
SnapshotTriggerDefinition
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.
prepareTrigger
in interface SnapshotTriggerDefinition
aggregateType
- The type of aggregate for which to create a triggerpublic SnapshotTrigger reconfigure(@Nonnull Class<?> aggregateType, @Nonnull SnapshotTrigger trigger)
SnapshotTriggerDefinition
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.
reconfigure
in interface SnapshotTriggerDefinition
aggregateType
- The type of aggregate for which this trigger was createdtrigger
- The trigger instance formerly created using SnapshotTriggerDefinition.prepareTrigger(Class)
trigger
instance.Copyright © 2010–2023. All rights reserved.