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 keyV
- the type of the Map entry valueR
- the type of value returned by the EntryProcessorT
- 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected InvocableMap.EntryProcessor<K,V,R>
f_processor
The underlying entry processor.-
Fields inherited from class com.tangosol.util.AsynchronousAgent
m_control, m_iOrderId
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractAsynchronousProcessor(InvocableMap.EntryProcessor<K,V,R> processor, int iUnitOrderId)
Construct AbstractAsynchronousProcessor instance.protected
AbstractAsynchronousProcessor(InvocableMap.EntryProcessor<K,V,R> processor, int iUnitOrderId, Executor executor)
Construct AbstractAsynchronousProcessor instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description InvocableMap.EntryProcessor<K,V,R>
getProcessor()
Obtain the underlying entry processor.int
getUnitOfOrderId()
Return a unit-of-order id associated with this processor.abstract void
onComplete()
Called after the processor has been notified about all possible partial results or failures and no more are forthcoming.abstract void
onException(Throwable eReason)
Called if any part of the operation failed for any reason.abstract void
onResult(Map.Entry<K,R> entry)
Called when there is a partial result of the asynchronous execution.R
process(InvocableMap.Entry<K,V> entry)
Not supported.Map<K,R>
processAll(Set<? extends InvocableMap.Entry<K,V>> setEntries)
Not supported.-
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
-
f_processor
protected final InvocableMap.EntryProcessor<K,V,R> f_processor
The underlying entry processor.
-
-
Constructor Detail
-
AbstractAsynchronousProcessor
protected AbstractAsynchronousProcessor(InvocableMap.EntryProcessor<K,V,R> processor, int iUnitOrderId)
Construct AbstractAsynchronousProcessor instance.- Parameters:
processor
- the underlyingInvocableMap.EntryProcessor
iUnitOrderId
- the unit-of-order id for this processor
-
AbstractAsynchronousProcessor
protected AbstractAsynchronousProcessor(InvocableMap.EntryProcessor<K,V,R> processor, int iUnitOrderId, Executor executor)
Construct AbstractAsynchronousProcessor instance.- Parameters:
processor
- the underlyingInvocableMap.EntryProcessor
iUnitOrderId
- the unit-of-order id for this processorexecutor
- an optionalExecutor
to complete the future on, if not provided theDaemons.commonPool()
is used
-
-
Method Detail
-
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 ofInvocableMap
'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 seegetUnitOfOrderId()
.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 correspondingexecution
and calls toonResult(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 correspondingexecution
and calls toonComplete()
are going to happen in the exact same order.Note 1: The ordering guarantee is respected between
AsynchronousProcessors
andAsynchronousAggregator
s with the same unit-of-order id.
Note 2: There is no ordering guarantees between asynchronous and synchronous operations.- Overrides:
getUnitOfOrderId
in classAsynchronousAgent<T>
- Returns:
- the unit-of-order id associated with this processor
- See Also:
AbstractAsynchronousAggregator.getUnitOfOrderId()
,getUnitOfOrderId()
-
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 interfaceInvocableMap.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 interfaceInvocableMap.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
-
-