Interface CombiningState<InputT,​AccumT,​OutputT>

  • Type Parameters:
    InputT - the type of values added to the state
    AccumT - the type of accumulator
    OutputT - the type of value extracted from the state
    All Superinterfaces:
    GroupingState<InputT,​OutputT>, ReadableState<OutputT>, State

    @Experimental(STATE)
    public interface CombiningState<InputT,​AccumT,​OutputT>
    extends GroupingState<InputT,​OutputT>
    A 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.

    • Method Detail

      • read

        @Nonnull
        OutputT read()
        Description copied from interface: ReadableState
        Read the current value, blocking until it is available.

        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.

        Specified by:
        read in interface ReadableState<InputT>
      • getAccum

        AccumT getAccum()
        Read the merged accumulator for this state cell. It is implied that reading the state involves reading the accumulator, so readLater() is sufficient to prefetch for this.
      • addAccum

        void addAccum​(AccumT accum)
        Add an accumulator to this state cell. Depending on implementation this may immediately merge it with the previous accumulator, or may buffer this accumulator for a future merge.
      • mergeAccumulators

        AccumT mergeAccumulators​(java.lang.Iterable<AccumT> accumulators)
        Merge the given accumulators according to the underlying Combine.CombineFn.