Class AsynchronousAggregator<K,V,P,R>
- java.lang.Object
-
- com.tangosol.util.AsynchronousAgent<R>
-
- com.tangosol.util.aggregator.AbstractAsynchronousAggregator<K,V,P,R>
-
- com.tangosol.util.aggregator.AsynchronousAggregator<K,V,P,R>
-
- Type Parameters:
K
- the type of the Map entry keysV
- the type of the Map entry valuesP
- the type of the intermediate result during the parallel stageR
- the type of the value returned by the StreamingAggregator
- All Implemented Interfaces:
FlowControl
,InvocableMap.EntryAggregator<K,V,R>
,Serializable
,Future<R>
public class AsynchronousAggregator<K,V,P,R> extends AbstractAsynchronousAggregator<K,V,P,R> implements InvocableMap.EntryAggregator<K,V,R>
A markerEntryAggregator
wrapper class that allows for an asynchronous invocation of the underlying aggregator. When used as aFuture
(without extending), this implementation will simply providethe result
of asynchronous streaming aggregation according to semantics of the correspondingEntryAggregator.aggregate
contract.More advanced use would require extending this class and overriding
onResult(P)
andonException(java.lang.Throwable)
methods. It's very important that overriding implementations of these methods must be non-blocking. For example, any use ofNamedCache
API is completely disallowed with the only exception ofAsynchronousAggregators
andAsynchronousProcessor(InvocableMap.EntryProcessor)
The underlying entry processor is guaranteed to have been fully executed when either
onResult()
oronException()
are called.Note 1: Neither this class nor its extensions need to be serializable. Only the underlying aggregator is serialized and sent to corresponding servers for execution.
Note 2: This feature is not available on Coherence*Extend clients.- Author:
- gg/mf 2012.12.21
- See Also:
AsynchronousProcessor
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Throwable
m_eReason
Reason for the failed operation.-
Fields inherited from class com.tangosol.util.aggregator.AbstractAsynchronousAggregator
m_aggregator
-
Fields inherited from class com.tangosol.util.AsynchronousAgent
m_control, m_iOrderId
-
-
Constructor Summary
Constructors Constructor Description AsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator)
Construct an AsynchronousAggregator for a given streaming aggregator.AsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, int iUnitOrderId)
Construct an AsynchronousAggregator for a given streaming aggregator.AsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, int iUnitOrderId, Executor executor)
Construct an AsynchronousAggregator for a given streaming aggregator.AsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, Executor executor)
Construct an AsynchronousAggregator for a given streaming aggregator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
onComplete()
Called after this asynchronous aggregator has been notified about all possible partial results or failures and no more are forthcoming.void
onException(Throwable eReason)
Called if the operation failed for any reason.void
onResult(P result)
Called when the aggregation result is available.-
Methods inherited from class com.tangosol.util.aggregator.AbstractAsynchronousAggregator
aggregate, getAggregator, getUnitOfOrderId
-
Methods inherited from class com.tangosol.util.AsynchronousAgent
bind, cancel, checkBacklog, complete, completeExceptionally, drainBacklog, flush, get, get, getCompletableFuture, getException, getResult, isCancelled, isCompletedExceptionally, isDone
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.tangosol.util.InvocableMap.EntryAggregator
aggregate
-
-
-
-
Field Detail
-
m_eReason
protected volatile Throwable m_eReason
Reason for the failed operation.
-
-
Constructor Detail
-
AsynchronousAggregator
public AsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator)
Construct an AsynchronousAggregator for a given streaming aggregator.- Parameters:
aggregator
- the underlying streaming aggregator
-
AsynchronousAggregator
public AsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, Executor executor)
Construct an AsynchronousAggregator for a given streaming aggregator.- Parameters:
aggregator
- the underlying streaming aggregatorexecutor
- an optionalExecutor
to complete the future on, if not provided theDaemons.commonPool()
is used
-
AsynchronousAggregator
public AsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, int iUnitOrderId)
Construct an AsynchronousAggregator for a given streaming aggregator.- Parameters:
aggregator
- the underlying streaming aggregatoriUnitOrderId
- the unit-of-order id for this aggregator
-
AsynchronousAggregator
public AsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, int iUnitOrderId, Executor executor)
Construct an AsynchronousAggregator for a given streaming aggregator.- Parameters:
aggregator
- the underlying streaming aggregatoriUnitOrderId
- the unit-of-order id for this aggregatorexecutor
- an optionalExecutor
to complete the future on, if not provided theDaemons.commonPool()
is used
-
-
Method Detail
-
onResult
public void onResult(P result)
Called when the aggregation result is available.For ordering guarantees see
AbstractAsynchronousAggregator.getUnitOfOrderId()
.Note: Overriding implementations of this method must be non-blocking.
-
onException
public void onException(Throwable eReason)
Called if the operation failed for any reason.Note: Overriding implementations of this method must be non-blocking.
- Specified by:
onException
in classAbstractAsynchronousAggregator<K,V,P,R>
- Parameters:
eReason
- the reason of failure
-
onComplete
public void onComplete()
Description copied from class:AbstractAsynchronousAggregator
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 seeAbstractAsynchronousAggregator.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.- Specified by:
onComplete
in classAbstractAsynchronousAggregator<K,V,P,R>
-
-