Interface Aggregator<I,R>

Type Parameters:
I - input type
R - result type
All Superinterfaces:
Serializable

public interface Aggregator<I,R> extends Serializable
Defines a contract for all aggregators. Exposes API for parallel two-phase aggregations: - accumulation of input entries by multiple instance of aggregators - combining all aggregators into one to calculate the final result

Aggregator does not have to be thread-safe. accumulate() and combine() calls may be interwoven.

The very instance passed to an aggregate() method will not be used at all. It is just a prototype object that will be cloned using serialization, since each partition gets its own instance of an aggregator. In this way the aggregator is not used by multiple-threads. Each thread gets its own aggregator instance.

Since:
3.8
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accumulate(I input)
    Accumulates the given entries.
    Returns the result of the aggregation.
    void
    combine(Aggregator aggregator)
    Incorporates the intermediary result of the given aggregator to this instance of the aggregator.
    default void
    Called after the last call to combine on a specific instance.
    default void
    Called after the last call to combine on a specific instance.
  • Method Details

    • accumulate

      void accumulate(I input)
      Accumulates the given entries.
      Parameters:
      input - input to accumulate.
    • onAccumulationFinished

      default void onAccumulationFinished()
      Called after the last call to combine on a specific instance. Enables disposing of the intermediary state. This should be a very fast operation that just disposes unnecessary state (if applicable).

      IMPORTANT: It may not be called if the instance aggregator does not take part in the accumulation phase. It's caused by the fact that the aggregation may be run in a parallel way and each thread gets a clone of the aggregator.

    • combine

      void combine(Aggregator aggregator)
      Incorporates the intermediary result of the given aggregator to this instance of the aggregator. The given aggregator has to be of the same class as the one that the method is being called on. Enables merging the intermediary state from a given aggregator. It is used when the aggregation is split into a couple of aggregators.
      Parameters:
      aggregator - aggregator providing intermediary results to be combined into the results of this aggregator. The given aggregator has to be of the same class as the one that the method is being called on.
    • onCombinationFinished

      default void onCombinationFinished()
      Called after the last call to combine on a specific instance. Enables disposing of the intermediary state. This should be a very fast operation that just disposes unnecessary state (if applicable).

      IMPORTANT: It may not be called if the instance aggregator does not take part in the combination phase. It's caused by the fact that the aggregation may be run in a parallel way and each thread gets a clone of the aggregator.

    • aggregate

      R aggregate()
      Returns the result of the aggregation. The result may be calculated in this call or cached by the aggregator.
      Returns:
      returns the result of the aggregation.