Interface InvocableMap.StreamingAggregator<K,V,P,R>
- Type Parameters:
K- the type of the Map entry keysV- the type of the Map entry valuesP- the type of the partial resultR- the type of the final result
- All Superinterfaces:
InvocableMap.EntryAggregator<K,V, R>, Serializable
- All Known Implementing Classes:
AbstractAggregator, AbstractBigDecimalAggregator, AbstractComparableAggregator, AbstractDoubleAggregator, AbstractLongAggregator, BigDecimalAverage, BigDecimalMax, BigDecimalMin, BigDecimalSum, ComparableMax, ComparableMin, CompositeAggregator, CompositeAggregator.Parallel, Count, DistinctValues, DoubleAverage, DoubleMax, DoubleMin, DoubleSum, GroupAggregator, GroupAggregator.Parallel, LongMax, LongMin, LongSum, PartitionedJCacheStatistics.PartitionedCacheStatisticsAggregator, PartitionedJCacheStatistics.PartitionedCacheStatisticsClear, PriorityAggregator, QueryRecorder, ReducerAggregator, ScriptAggregator, TopNAggregator
- Enclosing interface:
InvocableMap<K,V>
InvocableMap.EntryAggregator that
processes entries in a streaming fashion and provides better control
over execution characteristics.
It is strongly recommended that all new custom aggregator implementations
implement this interface directly and override default implementation of
the characteristics() method which intentionally errs on a
conservative side.
- Since:
- Coherence 3.1
- Author:
- cp/gg/jh 2005.07.19, as 2014.06.14
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe state of a continuously maintained aggregation result after an entry has been retracted. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intA flag requiring this aggregator to execute member-by-member.static final intA flag requiring this aggregator to execute partition-by-partition.static final intA flag specifying that this aggregator supports long-lived, incremental maintenance.static final intA flag specifying that this aggregator should be executed in parallel.static final intA flag specifying that this aggregator is only interested in entries that are present in the cache and that the entries which are not present should never be passed to theaccumulate(Entry)method.static final intA flag specifying that this aggregator retainsInvocableMap.Entryinstances passed toaccumulate(Entry)method, which will force creation of a separateInvocableMap.Entryinstance for each cache entry.static final intA flag specifying that this aggregator should be executed serially.static final intA flag specifying that this aggregator can create and restore an exact maintenance-state snapshot usingsnapshotState()andrestoreState(Object). -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccumulate(InvocableMap.Entry<? extends K, ? extends V> entry) Accumulate one entry into the result.default booleanaccumulate(Streamer<? extends InvocableMap.Entry<? extends K, ? extends V>> streamer) Accumulate multiple entries into the result.default Raggregate(Set<? extends InvocableMap.Entry<? extends K, ? extends V>> setEntries) Process a set of InvocableMap.Entry objects in order to produce an aggregated result.default intA bit mask representing the set of characteristics of this aggregator.booleanMerge another partial result into the result.Return the final result of the aggregation.default RfinalizeResult(Converter<Binary, ?> convFromInternal) Return the final result of the aggregation.Return the current maintenance status of this aggregator.Return the partial result of the aggregation.default booleanA convenience accessor to check if this streamer isALLOW_INCONSISTENCIES.default booleanA convenience accessor to check if this streamer isBY_MEMBER.default booleanA convenience accessor to check if this streamer isBY_PARTITION.default booleanA convenience accessor to check if this aggregator supports the continuous aggregation lifecycle.default booleanA convenience accessor to check if this streamer isPARALLEL.default booleanA convenience accessor to check if this streamer isPRESENT_ONLY.default booleanA convenience accessor to check if this streamer isRETAINS_ENTRIES.default booleanisSerial()A convenience accessor to check if this streamer isSERIAL.default booleanReturn whether this aggregator supports exact maintenance-state snapshots for transfer and persistence.default voidrestoreState(Object state) Restore a maintenance-state snapshot into this empty supplied instance.retract(InvocableMap.Entry<? extends K, ? extends V> entry) Retract the contribution of a single entry from the aggregation result.default ObjectReturn a detached, serializer-compatible snapshot of the state required to continue incremental maintenance.supply()Create a new instance of this aggregator.update(InvocableMap.Entry<? extends K, ? extends V> entry) Replace the contribution of an entry that was present before and remains present after a map update.
-
Field Details
-
PARALLEL
static final int PARALLELA flag specifying that this aggregator should be executed in parallel.The execution granularity can be specified by combining this flag with either
BY_MEMBERorBY_PARTITION, which are mutually exclusive. If neither is specified, Coherence is free to choose member or partition granularity using current service pressure and other internal metrics.- See Also:
-
SERIAL
static final int SERIALA flag specifying that this aggregator should be executed serially.The execution granularity can be specified by combining this flag with either
BY_MEMBERorBY_PARTITION, which are mutually exclusive. If neither is specified, Coherence is free to choose member or partition granularity using current service pressure and other internal metrics.- See Also:
-
BY_MEMBER
static final int BY_MEMBERA flag requiring this aggregator to execute member-by-member.Each storage member processes its complete local entry set as one partial aggregation. Coherence will not subdivide that work by partition, even when the aggregator is
PARALLEL.This flag is mutually exclusive with
BY_PARTITION.- See Also:
-
BY_PARTITION
static final int BY_PARTITIONA flag requiring this aggregator to execute partition-by-partition. The entries from each partition are processed independently and an independent partial result is created for every partition represented by the request.A storage member combines its partition partials into one member partial before sending it to the caller. The guarantee is about aggregation granularity; it does not require partitions to execute concurrently when the service is under pressure.
This flag is mutually exclusive with
BY_MEMBER.- See Also:
-
RETAINS_ENTRIES
static final int RETAINS_ENTRIESA flag specifying that this aggregator retainsInvocableMap.Entryinstances passed toaccumulate(Entry)method, which will force creation of a separateInvocableMap.Entryinstance for each cache entry.Please note that this flag is specified by default for backwards compatibility reasons, but if the aggregator does not retain entries it should be "unset" by overriding
characteristics()method in order to reduce the amount of garbage that is created during the aggregation.- See Also:
-
PRESENT_ONLY
static final int PRESENT_ONLYA flag specifying that this aggregator is only interested in entries that are present in the cache and that the entries which are not present should never be passed to theaccumulate(Entry)method.- See Also:
-
ALLOW_INCONSISTENCIES
static final int ALLOW_INCONSISTENCIESA flag specifying that this aggregator may provideentriesthat are not consistent with the providedFilter.Note: Coherence will ensure only entries that match the provided
Filterare passed to the aggregator, which can result in repeat query evaluations if targeted partitions are concurrently modified during query evaluation. This option allows Coherence to relax this contract.- See Also:
-
CONTINUOUS
static final int CONTINUOUSA flag specifying that this aggregator supports long-lived, incremental maintenance.An aggregator with this characteristic must return an empty aggregator from
supply(), must not retain entries, and must return a non-destructive partial result fromgetPartialResult(). It must also implementretract(Entry)and explicitly returnInvocableMap.StreamingAggregator.RetractionResult.REBUILD_REQUIREDwhen it cannot maintain a correct result after a removal. ItsObject.equals(Object)andObject.hashCode()implementations must be based solely on serialized definition state so equivalent registrations can be identified after serialization.- See Also:
-
STATE_CHECKPOINTABLE
static final int STATE_CHECKPOINTABLEA flag specifying that this aggregator can create and restore an exact maintenance-state snapshot usingsnapshotState()andrestoreState(Object).This characteristic is meaningful only together with
CONTINUOUS. Snapshot and restore implementations must preserve all information required for future retractions, not merely the partial result used for distributed combination.- See Also:
-
-
Method Details
-
supply
InvocableMap.StreamingAggregator<K,V, supply()P, R> Create a new instance of this aggregator.- Returns:
- a StreamAggregator
-
accumulate
default boolean accumulate(Streamer<? extends InvocableMap.Entry<? extends K, ? extends V>> streamer) Accumulate multiple entries into the result.Important note: The default implementation of this method provides necessary logic for aggregation short-circuiting and should rarely (if ever) be overridden by the custom aggregator implementation.
- Parameters:
streamer- aStreamerthat can be used to iterate over entries to add- Returns:
trueto continue the aggregation, andfalseto signal to the caller that the result is ready and the aggregation can be short-circuited
-
accumulate
Accumulate one entry into the result.- Parameters:
entry- the entry to accumulate into the aggregation result- Returns:
trueto continue the aggregation, andfalseto signal to the caller that the result is ready and the aggregation can be short-circuited
-
retract
default InvocableMap.StreamingAggregator.RetractionResult retract(InvocableMap.Entry<? extends K, ? extends V> entry) Retract the contribution of a single entry from the aggregation result.When the supplied entry is a
MapTrigger.Entry, an implementation should retract the entry's original value. Otherwise, it should retract the value represented by the supplied entry.The default implementation cannot retract an entry and requires the caller to rebuild the aggregation result.
- Parameters:
entry- the entry to retract- Returns:
- the state of the aggregation result after the retraction
-
update
default InvocableMap.StreamingAggregator.RetractionResult update(InvocableMap.Entry<? extends K, ? extends V> entry) Replace the contribution of an entry that was present before and remains present after a map update.The supplied entry is expected to be a
MapTrigger.Entryexposing both its original and current values. The default implementation retracts the original contribution, accumulates the current contribution, and therefore preserves the semantics of an update for aggregators that do not provide a specialized implementation.- Parameters:
entry- the updated entry- Returns:
- the state of the aggregation result after the update
-
getMaintenanceStatus
Return the current maintenance status of this aggregator.This method is evaluated after an update has been fully applied, so an aggregator may report
InvocableMap.StreamingAggregator.RetractionResult.STALE_BOUNDfromretract(Entry)and returnInvocableMap.StreamingAggregator.RetractionResult.UPDATEDhere if accumulating the replacement value restored an exact result.- Returns:
- the current maintenance status
-
snapshotState
Return a detached, serializer-compatible snapshot of the state required to continue incremental maintenance.This method is used only when
STATE_CHECKPOINTABLEis advertised. The default implementation does not support state checkpointing.- Returns:
- a detached maintenance-state snapshot
- Throws:
UnsupportedOperationException- if state checkpointing is not supported
-
restoreState
Restore a maintenance-state snapshot into this empty supplied instance.This method is used only when
STATE_CHECKPOINTABLEis advertised. The default implementation does not support state checkpointing.- Parameters:
state- the snapshot returned bysnapshotState()- Throws:
UnsupportedOperationException- if state checkpointing is not supported
-
combine
Merge another partial result into the result.- Parameters:
partialResult- the partial result to merge- Returns:
trueto continue the aggregation, andfalseto signal to the caller that the result is ready and the aggregation can be short-circuited
-
getPartialResult
P getPartialResult()Return the partial result of the aggregation.- Returns:
- the partial result of the aggregation
-
finalizeResult
R finalizeResult()Return the final result of the aggregation.- Returns:
- the final result of the aggregation
-
finalizeResult
Return the final result of the aggregation.This method has a default implementation that simply calls
finalizeResult()in order to avoid compilation errors and preserve backwards compatibility of custom aggregator implementations, even though it would make more sense to do it the other way around if we were designing this API from scratch.The unfortunate consequence is that even if you override this method in order to use the provided converter, you still need to implement
finalizeResult()method, although you could simply implement it to throwjava.lang.UnsupportedOperationException.- Parameters:
convFromInternal- converter that can be used to convert result from internal format- Returns:
- the final result of the aggregation
- Since:
- 24.09
-
characteristics
default int characteristics()A bit mask representing the set of characteristics of this aggregator.By default, characteristics are a combination of
PARALLELandRETAINS_ENTRIES, which is sub-optimal and should be overridden by the aggregator implementation if the aggregator does not need to retain entries (which is often the case).- Returns:
- a bit mask representing the set of characteristics of this aggregator
- See Also:
-
isParallel
-
isSerial
-
isByMember
-
isByPartition
default boolean isByPartition()A convenience accessor to check if this streamer isBY_PARTITION.- Returns:
trueif this streamer isBY_PARTITION, false otherwise
-
isRetainsEntries
default boolean isRetainsEntries()A convenience accessor to check if this streamer isRETAINS_ENTRIES.- Returns:
trueif this streamer isRETAINS_ENTRIES, false otherwise
-
isPresentOnly
default boolean isPresentOnly()A convenience accessor to check if this streamer isPRESENT_ONLY.- Returns:
trueif this streamer isPRESENT_ONLY, false otherwise
-
isAllowInconsistencies
default boolean isAllowInconsistencies()A convenience accessor to check if this streamer isALLOW_INCONSISTENCIES.- Returns:
trueif this streamer isALLOW_INCONSISTENCIES, false otherwise
-
isContinuous
default boolean isContinuous()A convenience accessor to check if this aggregator supports the continuous aggregation lifecycle.- Returns:
trueif this aggregator supports continuous aggregation,falseotherwise
-
isStateCheckpointable
default boolean isStateCheckpointable()Return whether this aggregator supports exact maintenance-state snapshots for transfer and persistence.- Returns:
trueif this aggregator supports state checkpoints
-
aggregate
Description copied from interface:InvocableMap.EntryAggregatorProcess a set of InvocableMap.Entry objects in order to produce an aggregated result.- Specified by:
aggregatein interfaceInvocableMap.EntryAggregator<K,V, P> - Parameters:
setEntries- a Set of read-only InvocableMap.Entry objects to aggregate- Returns:
- the aggregated result from processing the entries
-