Class AggregateSnapshotDeletionStrategy.KeepHistoricSnapshots
- java.lang.Object
-
- dk.cloudcreate.essentials.components.eventsourced.aggregates.snapshot.AggregateSnapshotDeletionStrategy.KeepHistoricSnapshots
-
- All Implemented Interfaces:
AggregateSnapshotDeletionStrategy
- Enclosing interface:
- AggregateSnapshotDeletionStrategy
public static class AggregateSnapshotDeletionStrategy.KeepHistoricSnapshots extends Object implements AggregateSnapshotDeletionStrategy
Strategy that keeps all or a specific number of historic aggregate snapshots
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface dk.cloudcreate.essentials.components.eventsourced.aggregates.snapshot.AggregateSnapshotDeletionStrategy
AggregateSnapshotDeletionStrategy.DeleteAllHistoricSnapshots, AggregateSnapshotDeletionStrategy.KeepHistoricSnapshots
-
-
Constructor Summary
Constructors Constructor Description KeepHistoricSnapshots()Strategy that keeps all historic aggregate snapshotsKeepHistoricSnapshots(long numberOfHistoricSnapshotsToKeep)Strategy that keeps a specific number historic aggregate snapshots
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)longgetNumberOfHistoricSnapshotsToKeep()inthashCode()static AggregateSnapshotDeletionStrategy.KeepHistoricSnapshotskeepALimitedNumberOfHistoricSnapshots(long numberOfHistoricSnapshotsToKeep)Strategy that keeps all historic aggregate snapshotsstatic AggregateSnapshotDeletionStrategy.KeepHistoricSnapshotskeepAllHistoricSnapshots()Strategy that keeps all historic aggregate snapshotsbooleanrequiresExistingSnapshotDetailsToDetermineWhichAggregateSnapshotsToDelete()Guard method that determines if Aggregate Snapshot statistics are required in order to determine which Snapshots to delete<ID,AGGREGATE_IMPL_TYPE>
Stream<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>>resolveSnapshotsToDelete(List<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> existingSnapshots)Out of all the existing snapshots (loaded without the snapshot payload), return theAggregateSnapshot's that should be deleted
This method is called just prior to adding a newAggregateSnapshot, so if the purpose it to keep 3 snapshots, and we already have 3 snapshots, then this method should return aStreamcontaining the oldest snapshot, which will then be deletedStringtoString()
-
-
-
Constructor Detail
-
KeepHistoricSnapshots
public KeepHistoricSnapshots()
Strategy that keeps all historic aggregate snapshots
-
KeepHistoricSnapshots
public KeepHistoricSnapshots(long numberOfHistoricSnapshotsToKeep)
Strategy that keeps a specific number historic aggregate snapshots- Parameters:
numberOfHistoricSnapshotsToKeep- the number of historic aggregate snapshots to keep (must be >= 0)
-
-
Method Detail
-
keepALimitedNumberOfHistoricSnapshots
public static AggregateSnapshotDeletionStrategy.KeepHistoricSnapshots keepALimitedNumberOfHistoricSnapshots(long numberOfHistoricSnapshotsToKeep)
Strategy that keeps all historic aggregate snapshots- Parameters:
numberOfHistoricSnapshotsToKeep- the number of historic aggregate snapshots to keep- Returns:
- Strategy that keeps all historic aggregate snapshots
-
keepAllHistoricSnapshots
public static AggregateSnapshotDeletionStrategy.KeepHistoricSnapshots keepAllHistoricSnapshots()
Strategy that keeps all historic aggregate snapshots- Returns:
- Strategy that keeps all historic aggregate snapshots
-
requiresExistingSnapshotDetailsToDetermineWhichAggregateSnapshotsToDelete
public boolean requiresExistingSnapshotDetailsToDetermineWhichAggregateSnapshotsToDelete()
Description copied from interface:AggregateSnapshotDeletionStrategyGuard method that determines if Aggregate Snapshot statistics are required in order to determine which Snapshots to delete- Specified by:
requiresExistingSnapshotDetailsToDetermineWhichAggregateSnapshotsToDeletein interfaceAggregateSnapshotDeletionStrategy- Returns:
- true if
AggregateSnapshotRepository.aggregateUpdated(Object, AggregateEventStream)should fetch existingAggregateSnapshot's (without the payload) as input toAggregateSnapshotDeletionStrategy.resolveSnapshotsToDelete(List)or false if all existing snapshots can be deleted (solvesAggregateSnapshotDeletionStrategy.DeleteAllHistoricSnapshotswithout incurring additional DB queries)
-
resolveSnapshotsToDelete
public <ID,AGGREGATE_IMPL_TYPE> Stream<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> resolveSnapshotsToDelete(List<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> existingSnapshots)
Description copied from interface:AggregateSnapshotDeletionStrategyOut of all the existing snapshots (loaded without the snapshot payload), return theAggregateSnapshot's that should be deleted
This method is called just prior to adding a newAggregateSnapshot, so if the purpose it to keep 3 snapshots, and we already have 3 snapshots, then this method should return aStreamcontaining the oldest snapshot, which will then be deleted- Specified by:
resolveSnapshotsToDeletein interfaceAggregateSnapshotDeletionStrategy- Type Parameters:
ID- the id type for the aggregateAGGREGATE_IMPL_TYPE- the aggregate type implementation type- Parameters:
existingSnapshots- all the existing snapshots pertaining to a given aggregate instance- Returns:
- all the
AggregateSnapshot's that should be deleted
-
getNumberOfHistoricSnapshotsToKeep
public long getNumberOfHistoricSnapshotsToKeep()
-
-