InputT
- the type of values added to the stateAccumT
- the type of accumulatorOutputT
- the type of value extracted from the statepublic interface CombiningState<InputT,AccumT,OutputT> extends GroupingState<InputT,OutputT>
ReadableState
cell defined by a Combine.CombineFn
, accepting multiple input values,
combining them as specified into accumulators, and producing a single output value.
Implementations of this form of state are expected to implement GroupingState.add(InputT)
efficiently, not
via a sequence of read-modify-write.
Modifier and Type | Method and Description |
---|---|
void |
addAccum(AccumT accum)
Add an accumulator to this state cell.
|
AccumT |
getAccum()
Read the merged accumulator for this state cell.
|
AccumT |
mergeAccumulators(java.lang.Iterable<AccumT> accumulators)
Merge the given accumulators according to the underlying
Combine.CombineFn . |
OutputT |
read()
Read the current value, blocking until it is available.
|
CombiningState<InputT,AccumT,OutputT> |
readLater()
Indicate that the value will be read later.
|
add, isEmpty
@Nonnull OutputT read()
ReadableState
If there will be many calls to ReadableState.read()
for different state in short succession, you
should first call ReadableState.readLater()
for all of them so the reads can potentially be batched
(depending on the underlying implementation}.
The returned object should be independent of the underlying state. Any direct modification of the returned object should not modify state without going through the appropriate state interface, and modification to the state should not be mirrored in the returned object.
read
in interface ReadableState<OutputT>
AccumT getAccum()
readLater()
is sufficient to prefetch for this.void addAccum(AccumT accum)
AccumT mergeAccumulators(java.lang.Iterable<AccumT> accumulators)
Combine.CombineFn
.CombiningState<InputT,AccumT,OutputT> readLater()
ReadableState
This allows an implementation to start an asynchronous prefetch or to include this state in the next batch of reads.
readLater
in interface GroupingState<InputT,OutputT>
readLater
in interface ReadableState<OutputT>