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 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>
- 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:
AsynchronousAggregator
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected InvocableMap.StreamingAggregator<K,V,P,R>
m_aggregator
The underlying aggregator.-
Fields inherited from class com.tangosol.util.AsynchronousAgent
m_control, m_iOrderId
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractAsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, int iUnitOrderId)
Construct an AsynchronousAggregator for a given streaming aggregator.protected
AbstractAsynchronousAggregator(InvocableMap.StreamingAggregator<K,V,P,R> aggregator, int iUnitOrderId, Executor executor)
Construct an AsynchronousAggregator for a given streaming aggregator.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description R
aggregate(Set<? extends InvocableMap.Entry<? extends K,? extends V>> setEntries)
Not supported.InvocableMap.StreamingAggregator<K,V,P,R>
getAggregator()
Return the underlying streaming aggregator.int
getUnitOfOrderId()
Return a unit-of-order id associated with this aggregator.abstract void
onComplete()
Called after this asynchronous aggregator has been notified about all possible partial results or failures and no more are forthcoming.abstract void
onException(Throwable eReason)
Called if the operation failed for any reason.abstract void
onResult(P result)
Called when there is a partial result of the asynchronous execution.-
Methods inherited from class com.tangosol.util.AsynchronousAgent
bind, cancel, checkBacklog, complete, completeExceptionally, drainBacklog, flush, get, get, getCompletableFuture, getException, getResult, isCancelled, isCompletedExceptionally, isDone
-
-
-
-
Field Detail
-
m_aggregator
protected InvocableMap.StreamingAggregator<K,V,P,R> m_aggregator
The underlying aggregator.
-
-
Constructor Detail
-
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 aggregatoriUnitOrderId
- the unit-of-order id for this aggregator
-
AbstractAsynchronousAggregator
protected AbstractAsynchronousAggregator(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 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 seegetUnitOfOrderId()
.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 correspondingexecution
and calls toonResult(P)
are going to happen in the exact same order.Note 1: the ordering guarantee is respected between
AbstractAsynchronousAggregator
s andAsynchronousProcessor
s with the same unit-of-order id;
Note 2: there is no ordering guarantee between asynchronous and synchronous operations.- Overrides:
getUnitOfOrderId
in classAsynchronousAgent<R>
- Returns:
- the order id
- See Also:
getUnitOfOrderId()
,AbstractAsynchronousProcessor.getUnitOfOrderId()
-
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 interfaceInvocableMap.EntryAggregator<K,V,P>
- Parameters:
setEntries
- a Set of read-only InvocableMap.Entry objects to aggregate- Returns:
- the aggregated result from processing the entries
-
-