Class AbstractAsynchronousProcessor<K,V,R,T>

java.lang.Object
com.tangosol.util.AsynchronousAgent<T>
com.tangosol.util.processor.AbstractAsynchronousProcessor<K,V,R,T>
Type Parameters:
K - the type of the Map entry key
V - the type of the Map entry value
R - the type of value returned by the EntryProcessor
T - the type of the result
All Implemented Interfaces:
FlowControl, InvocableMap.EntryProcessor<K,V,R>, Serializable, Future<T>
Direct Known Subclasses:
AsynchronousProcessor, SingleEntryAsynchronousProcessor, StreamingAsynchronousProcessor

public abstract class AbstractAsynchronousProcessor<K,V,R,T> extends AsynchronousAgent<T> implements InvocableMap.EntryProcessor<K,V,R>
Abstract base class for asynchronous entry processors.
Since:
12.2.1
Author:
as 2015.01.26
See Also:
  • Field Details

  • Constructor Details

    • AbstractAsynchronousProcessor

      protected AbstractAsynchronousProcessor(InvocableMap.EntryProcessor<K,V,R> processor, int iUnitOrderId)
      Construct AbstractAsynchronousProcessor instance.
      Parameters:
      processor - the underlying InvocableMap.EntryProcessor
      iUnitOrderId - the unit-of-order id for this processor
  • Method Details

    • onResult

      public abstract void onResult(Map.Entry<K,R> entry)
      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 processor invocations see getUnitOfOrderId().

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

      Parameters:
      entry - an entry holding the key and a result of the operation for the given key
    • onComplete

      public abstract void onComplete()
      Called after the processor has been notified about all possible partial results or failures and no more are forthcoming. As long as this processor 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.invoke
          ...
          onResult
          onComplete
      
        cache.invoke
          ...
          onException
          onComplete
      
        cache.invokeAll
          ...
           onResult
           onException
           onException
           onResult
           onComplete
       
      For ordering guarantees across processors see getUnitOfOrderId().

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

    • onException

      public abstract void onException(Throwable eReason)
      Called if any part of the operation failed for any reason. For operations that span multiple partitions this method could be called more than once. However, unless subclasses override this method, any failure will "complete" the operation.

      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 processor. By default, the unit-of-order id is assigned to the calling thread's hashCode.

      If two consecutive "invoke" calls are made using AsynchronousProcessors with the same order id and the same key set, then the corresponding execution and calls to onResult(java.util.Map.Entry<K, R>) are going to happen in the exact same order.

      If two consecutive "invoke" calls are made using AsynchronousProcessors with the same order id and the same partition set, then the the corresponding execution and calls to onComplete() are going to happen in the exact same order.

      Note 1: The ordering guarantee is respected between AsynchronousProcessors and AsynchronousAggregators with the same unit-of-order id.
      Note 2: There is no ordering guarantees between asynchronous and synchronous operations.

      Overrides:
      getUnitOfOrderId in class AsynchronousAgent<T>
      Returns:
      the unit-of-order id associated with this processor
      See Also:
    • getProcessor

      public InvocableMap.EntryProcessor<K,V,R> getProcessor()
      Obtain the underlying entry processor.
      Returns:
      the underlying entry processor
    • process

      public R process(InvocableMap.Entry<K,V> entry)
      Not supported.
      Specified by:
      process in interface InvocableMap.EntryProcessor<K,V,R>
      Parameters:
      entry - the Entry to process
      Returns:
      the result of the processing, if any
    • processAll

      public Map<K,R> processAll(Set<? extends InvocableMap.Entry<K,V>> setEntries)
      Not supported.
      Specified by:
      processAll in interface InvocableMap.EntryProcessor<K,V,R>
      Parameters:
      setEntries - a Set of InvocableMap.Entry objects to process
      Returns:
      a Map containing the results of the processing, up to one entry for each InvocableMap.Entry that was processed, keyed by the keys of the Map that were processed, with a corresponding value being the result of the processing for each key