Class AbstractAsynchronousAggregator<K,V,P,R>

java.lang.Object
com.tangosol.util.AsynchronousAgent<R>
com.tangosol.util.aggregator.AbstractAsynchronousAggregator<K,V,P,R>
Type Parameters:
K - the type of the Map entry keys
V - the type of the Map entry values
P - the type of the intermediate result during the parallel stage
R - the type of the value returned by the StreamingAggregator
All Implemented Interfaces:
FlowControl, InvocableMap.EntryAggregator<K,V,R>, Serializable, Future<R>
Direct Known Subclasses:
AsynchronousAggregator

public abstract class AbstractAsynchronousAggregator<K,V,P,R> extends AsynchronousAgent<R> implements InvocableMap.EntryAggregator<K,V,R>
Abstract base class for asynchronous entry aggregators.
Author:
gg/bb 2015.04.02
See Also:
  • Field Details

  • Constructor Details

    • AbstractAsynchronousAggregator

      protected AbstractAsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, int iUnitOrderId)
      Construct an AsynchronousAggregator for a given streaming aggregator.
      Parameters:
      aggregator - the underlying streaming aggregator
      iUnitOrderId - the unit-of-order id for this aggregator
  • Method Details

    • onResult

      public abstract void onResult(P result)
      Called when there is a partial result of the asynchronous execution.

      For a given request, calls to this method and onException(java.lang.Throwable) may come concurrently.

      For ordering guarantees across different aggregator invocations see getUnitOfOrderId().

      Note: Overriding implementations of this method must be non-blocking.

      Parameters:
      result - the partial result holder
    • onComplete

      public abstract void onComplete()
      Called after this asynchronous aggregator has been notified about all possible partial results or failures and no more are forthcoming.

      As long as this aggregator was submitted to any of InvocableMap's methods, this method is guaranteed to be called once and only once.

      Possible call back sequences are:

        cache.aggregate
          ...
          onResult
          onComplete
      
        cache.aggregate
          ...
          onException
          onComplete
      
        cache.aggregate
          ...
           onResult
           onException
           onException
           onResult
           onComplete
       
      For ordering guarantees across processors see getUnitOfOrderId().

      Note:

      Overriding implementations of this method must be non-blocking.

      If the StreamingAggregator signaled to short-circuit the aggregation while combining partial results, onComplete() could be called before all the results are received.

    • onException

      public abstract void onException(Throwable eReason)
      Called if the operation failed for any reason.

      For a given request, calls to this method and onResult(P) may come concurrently.

      Note: Overriding implementations of this method must be non-blocking.

      Parameters:
      eReason - the reason of failure
    • getUnitOfOrderId

      public int getUnitOfOrderId()
      Return a unit-of-order id associated with this aggregator. By default, the unit-of-order id is assigned to the calling thread's hashCode.

      If two consecutive "aggregate" calls made using AsynchronousAggregators with the same order id and involve the same key set, then the corresponding execution and calls to onResult(P) are going to happen in the exact same order.

      Note 1: the ordering guarantee is respected between AbstractAsynchronousAggregators and AsynchronousProcessors with the same unit-of-order id;
      Note 2: there is no ordering guarantee between asynchronous and synchronous operations.

      Overrides:
      getUnitOfOrderId in class AsynchronousAgent<R>
      Returns:
      the order id
      See Also:
    • getAggregator

      public InvocableMap.StreamingAggregator<K,V,P,R> getAggregator()
      Return the underlying streaming aggregator.
      Returns:
      the underlying aggregator
    • aggregate

      public R aggregate(Set<? extends InvocableMap.Entry<? extends K,? extends V>> setEntries)
      Not supported.
      Specified by:
      aggregate in interface InvocableMap.EntryAggregator<K,V,P>
      Parameters:
      setEntries - a Set of read-only InvocableMap.Entry objects to aggregate
      Returns:
      the aggregated result from processing the entries