com.hazelcast.aggregation

## Class Aggregator<I,R>

- java.lang.Object
- - com.hazelcast.aggregation.Aggregator<I,R>

- Type Parameters:
    `I` - input type
    `R` - result type
  All Implemented Interfaces:
    Serializable

      public abstract class Aggregator<I,R>
      extends Object
      implements Serializable

  Base class 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
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Aggregator()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | `accumulate(I input)` Accumulates the given entries.
    `abstract R` | `aggregate()` Returns the result of the aggregation.
    `abstract void` | `combine(Aggregator aggregator)` Incorporates the intermediary result of the given aggregator to this instance of the aggregator.
    `void` | `onAccumulationFinished()` Called after the last call to combine on a specific instance.
    `void` | `onCombinationFinished()` Called after the last call to combine on a specific instance.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Aggregator

          public Aggregator()

  - ### Method Detail

    - #### accumulate

          public abstract void accumulate(I input)

      Accumulates the given entries.
      Parameters:
        `input` - input to accumulate.

    - #### onAccumulationFinished

          public 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

          public abstract 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

          public 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

          public abstract 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.

Copyright © 2019. All rights reserved.