Class ClusteredTaskManager<T,A,R>
- java.lang.Object
-
- com.oracle.coherence.concurrent.executor.ClusteredTaskManager<T,A,R>
-
- Type Parameters:
T- theTasktypeA- the mutable accumulation type of the reduction operation by theTask.CollectorR- the result type of the reduction operation performed by theTask.Collector
- All Implemented Interfaces:
com.oracle.coherence.concurrent.executor.internal.LiveObject,ExternalizableLite,PortableObject,Serializable
public class ClusteredTaskManager<T,A,R> extends Object implements ExternalizableLite, com.oracle.coherence.concurrent.executor.internal.LiveObject, PortableObject
Manages the definition and current state of an individualTaskbeing orchestrated by anTaskExecutorService.- Since:
- 21.12
- Author:
- bo
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description protected Task.Collector<T,A,R>m_collectorTheTask.Collectorfor theTaskresult(s).protected Remote.Predicate<? super R>m_completionPredicateTheRemote.Predicateto determine if theTaskis complete, based on a collected result.protected Task.CompletionRunnable<? super R>m_completionRunnableThe runnable to call when theTaskis complete.protected intm_cPendingExecutionPlanOptimizationCountThe number of potential optimizations that can occurred to theExecutionPlansince it was last optimized.protected intm_cPendingExecutionStrategyUpdateCountThe number of events/updates/changes that have occurred since the last time theExecutionStrategywas evaluated, which may impact theExecutionPlan.protected Debuggingm_debuggingprotected ExecutionPlanm_executionPlanThe currentExecutionPlan.protected ExecutionStrategym_executionStrategyprotected booleanm_fCancelledA flag to indicate if theTaskis now cancelled, in which case no further results will be accepted and no future updates will be published.protected booleanm_fCompletedA flag to indicate if theTaskis now completed, in which case no further results will be accepted and no future updates will be published.protected booleanm_fRunCompletionRunnableA flag to indicate whether to run the completionRunnable or not.protected Result<R>m_lastResultThe last collected result for theTask.protected longm_lCurrentResultGenerationMonotonically increasing generation counter indicating how many times a result was provided.protected List<Result<T>>m_listResultsprotected longm_lProcessedResultGenerationThe generation counter of the last time the results were evaluated.protected longm_lTaskSequenceThe partition based sequence number of theTask.protected intm_nPartitionIdThe partition ID of theTask.protected intm_nResultVersionThe lastResult version represented by a monotonically increasing integer value.protected Durationm_retainDurationprotected Stringm_sTaskIdThe unique identity of theTask.protected ClusteredTaskManager.Statem_stateThe current state of theClusteredTaskManager.protected Task<T>m_taskTheTask.protected static Filter<TaskExecutorService.ExecutorInfo>RUNNING_EXECUTOR_FILTERFilterfor obtaining only JOINING and RUNNING executors.
-
Constructor Summary
Constructors Constructor Description ClusteredTaskManager()Constructs anClusteredTaskManager(required for serialization).ClusteredTaskManager(String sTaskId, Task<T> task, ExecutionStrategy executionStrategy, Task.Collector<? super T,A,R> collector, Remote.Predicate<? super R> completionPredicate, Task.CompletionRunnable<? super R> completionRunnable, Duration retainDuration, OptionsByType<Task.Option> optionsByType)Constructs aClusteredTaskManagerfor the specifiedTask.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanasyncEvaluateExecutionStrategy(CacheService service, EnumSet<ExecutionStrategy.EvaluationRationale> rationales)Asynchronously evaluate theExecutionStrategyfor theTaskand if necessary, update theExecutionPlanandResultmap.protected booleanasyncEvaluateResult(Result<R> originalResult)voidasyncProcessChanges(CacheService service, String key, com.oracle.coherence.concurrent.executor.internal.Cause cause)Asynchronously processes the changes that have recently occurred on theClusteredTaskManager.protected voidcleanProperties(CacheService service)Clean up the task properties.protected voidcleanup(CacheService service, String sKey)Cleanup metadata associated with the given task key.Task.CompletionRunnable<? super R>getCompletionRunnable()Obtains theTask.CompletionRunnable.DebugginggetDebugging()Result<R>getLastResult()Get the last collectedResult.protected com.tangosol.internal.tracing.SpanContextgetParentSpanContext()Return theSpanContextof the span that enqueued this task.intgetPartitionId()Gets the partition ID.intgetResultVersion()Get the version number of the latest result.DurationgetRetainDuration()booleangetRunCompletionRunnable()Obtains the flag to indicate if we need to run theTask.CompletionRunnable.ClusteredTaskManager.StategetState()Obtains the state of theTask.Task<T>getTask()Obtains theTaskto be executed.StringgetTaskId()Obtains the unique identity of theTask.longgetTaskSequence()Gets the partition basedTasksequence number.booleanisCancelled()Determines if theTaskhas been cancelled.booleanisCompleted()Determines if theTaskhas completed execution and can now be removed.booleanisDone()Returns true if theTaskcompleted.booleanisOwner(String executorId)ComposableContinuationonDeleted(CacheService service, InvocableMap.Entry entry, com.oracle.coherence.concurrent.executor.internal.Cause cause)Effectively, a no-op.ComposableContinuationonInserted(CacheService service, InvocableMap.Entry entry, com.oracle.coherence.concurrent.executor.internal.Cause cause)ComposableContinuationonProcess(CacheService service, InvocableMap.Entry entry, com.oracle.coherence.concurrent.executor.internal.Cause cause)Returns aComposableContinuationto invoke based on the current state.ComposableContinuationonUpdated(CacheService service, InvocableMap.Entry entry, com.oracle.coherence.concurrent.executor.internal.Cause cause)voidreadExternal(PofReader in)Restore the contents of a user type instance by reading its state using the specified PofReader object.voidreadExternal(DataInput in)Restore the contents of this object by loading the object's state from the passed DataInput object.voidsetPartitionId(int nPartitionId)Sets theTaskpartition ID.voidsetResult(Result<T> result)voidsetRunCompletionRunnable(boolean value)Sets the flag to indicate if we need to run theTask.CompletionRunnable.voidsetState(ClusteredTaskManager.State state)Sets the state of theTask.voidsetTaskSequence(long sequence)Sets the partition basedTasksequence number.StringtoString()voidwriteExternal(PofWriter out)Save the contents of a POF user type instance by writing its state using the specified PofWriter object.voidwriteExternal(DataOutput out)Save the contents of this object by storing the object's state into the passed DataOutput object.
-
-
-
Field Detail
-
RUNNING_EXECUTOR_FILTER
protected static final Filter<TaskExecutorService.ExecutorInfo> RUNNING_EXECUTOR_FILTER
Filterfor obtaining only JOINING and RUNNING executors.- Since:
- 22.06.7
-
m_lTaskSequence
protected volatile long m_lTaskSequence
The partition based sequence number of theTask.
-
m_nPartitionId
protected int m_nPartitionId
The partition ID of theTask.
-
m_executionStrategy
protected ExecutionStrategy m_executionStrategy
-
m_collector
protected Task.Collector<T,A,R> m_collector
TheTask.Collectorfor theTaskresult(s).
-
m_completionPredicate
protected Remote.Predicate<? super R> m_completionPredicate
TheRemote.Predicateto determine if theTaskis complete, based on a collected result.
-
m_completionRunnable
protected Task.CompletionRunnable<? super R> m_completionRunnable
The runnable to call when theTaskis complete.
-
m_fRunCompletionRunnable
protected boolean m_fRunCompletionRunnable
A flag to indicate whether to run the completionRunnable or not.
-
m_retainDuration
protected Duration m_retainDuration
-
m_debugging
protected Debugging m_debugging
-
m_executionPlan
protected ExecutionPlan m_executionPlan
-
m_cPendingExecutionStrategyUpdateCount
protected int m_cPendingExecutionStrategyUpdateCount
The number of events/updates/changes that have occurred since the last time theExecutionStrategywas evaluated, which may impact theExecutionPlan.
-
m_cPendingExecutionPlanOptimizationCount
protected int m_cPendingExecutionPlanOptimizationCount
The number of potential optimizations that can occurred to theExecutionPlansince it was last optimized.
-
m_nResultVersion
protected int m_nResultVersion
The lastResult version represented by a monotonically increasing integer value.
-
m_lCurrentResultGeneration
protected long m_lCurrentResultGeneration
Monotonically increasing generation counter indicating how many times a result was provided.
-
m_lProcessedResultGeneration
protected long m_lProcessedResultGeneration
The generation counter of the last time the results were evaluated.
-
m_fCompleted
protected volatile boolean m_fCompleted
A flag to indicate if theTaskis now completed, in which case no further results will be accepted and no future updates will be published.
-
m_fCancelled
protected volatile boolean m_fCancelled
A flag to indicate if theTaskis now cancelled, in which case no further results will be accepted and no future updates will be published.
-
m_state
protected volatile ClusteredTaskManager.State m_state
The current state of theClusteredTaskManager.
-
-
Constructor Detail
-
ClusteredTaskManager
public ClusteredTaskManager()
Constructs anClusteredTaskManager(required for serialization).
-
ClusteredTaskManager
public ClusteredTaskManager(String sTaskId, Task<T> task, ExecutionStrategy executionStrategy, Task.Collector<? super T,A,R> collector, Remote.Predicate<? super R> completionPredicate, Task.CompletionRunnable<? super R> completionRunnable, Duration retainDuration, OptionsByType<Task.Option> optionsByType)
Constructs aClusteredTaskManagerfor the specifiedTask.- Parameters:
sTaskId- the unique identity of theTaskbeing managedtask- theTaskto manageexecutionStrategy- theExecutionStrategycollector- theTask.Collectorfor resultscompletionPredicate- theRemote.Predicateto determine if aTaskis completecompletionRunnable- theTask.CompletionRunnableto call when aTaskis completeretainDuration- theDurationto retain aTaskafter it is completeoptionsByType- theOptionsByTypeto be used
-
-
Method Detail
-
onProcess
public ComposableContinuation onProcess(CacheService service, InvocableMap.Entry entry, com.oracle.coherence.concurrent.executor.internal.Cause cause)
Returns aComposableContinuationto invoke based on the current state. This may returnnullif no continuation is needed.- Parameters:
service- the associatedCacheServiceentry- the cacheInvocableMap.Entryfor the task being processedcause- theCausetriggered an update- Returns:
- a
ComposableContinuationto invoke based on the current state ornullif no continuation is needed
-
isOwner
public boolean isOwner(String executorId)
-
getTaskId
public String getTaskId()
Obtains the unique identity of theTask.- Returns:
- the unique identity of the
Task
-
getState
public ClusteredTaskManager.State getState()
Obtains the state of theTask.- Returns:
- the state of the
Task
-
setState
public void setState(ClusteredTaskManager.State state)
Sets the state of theTask.- Parameters:
state- the state to set to
-
getRunCompletionRunnable
public boolean getRunCompletionRunnable()
Obtains the flag to indicate if we need to run theTask.CompletionRunnable.- Returns:
- the flag to indicate if we need to run the
Task.CompletionRunnable.
-
setRunCompletionRunnable
public void setRunCompletionRunnable(boolean value)
Sets the flag to indicate if we need to run theTask.CompletionRunnable.- Parameters:
value- the flag to indicate if we need to run theTask.CompletionRunnable
-
getCompletionRunnable
public Task.CompletionRunnable<? super R> getCompletionRunnable()
Obtains theTask.CompletionRunnable.- Returns:
- the
Task.CompletionRunnable
-
asyncProcessChanges
public void asyncProcessChanges(CacheService service, String key, com.oracle.coherence.concurrent.executor.internal.Cause cause)
Asynchronously processes the changes that have recently occurred on theClusteredTaskManager.- Parameters:
service- theCacheServicethat owns theClusteredTaskManagerstatekey- theNamedCachekey for theClusteredTaskManagercause- the underlying eventCausethat triggered the processing
-
isCompleted
public boolean isCompleted()
Determines if theTaskhas completed execution and can now be removed.- Returns:
trueif theTaskhas completed execution,falseotherwise
-
isCancelled
public boolean isCancelled()
Determines if theTaskhas been cancelled.- Returns:
trueif theTaskhas been cancelled,falseotherwise
-
isDone
public boolean isDone()
Returns true if theTaskcompleted. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.- Returns:
truethe associatedTaskhas is donefalseotherwise
-
getLastResult
public Result<R> getLastResult()
Get the last collectedResult.- Returns:
- the last collected
Result
-
getResultVersion
public int getResultVersion()
Get the version number of the latest result.- Returns:
- the version number of the latest result
-
getPartitionId
public int getPartitionId()
Gets the partition ID.- Returns:
- the partition ID.
-
setPartitionId
public void setPartitionId(int nPartitionId)
Sets theTaskpartition ID.- Parameters:
nPartitionId- theTaskpartition ID to set to
-
getTaskSequence
public long getTaskSequence()
Gets the partition basedTasksequence number.- Returns:
- the partition based
Tasksequence number
-
setTaskSequence
public void setTaskSequence(long sequence)
Sets the partition basedTasksequence number.- Parameters:
sequence- theTasksequence number to set to
-
readExternal
public void readExternal(DataInput in) throws IOException
Description copied from interface:ExternalizableLiteRestore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
readExternalin interfaceExternalizableLite- Parameters:
in- the DataInput stream to read data from in order to restore the state of this object- Throws:
IOException- if an I/O exception occursNotActiveException- if the object is not in its initial state, and therefore cannot be deserialized into
-
writeExternal
public void writeExternal(DataOutput out) throws IOException
Description copied from interface:ExternalizableLiteSave the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
writeExternalin interfaceExternalizableLite- Parameters:
out- the DataOutput stream to write the state of this object to- Throws:
IOException- if an I/O exception occurs
-
readExternal
public void readExternal(PofReader in) throws IOException
Description copied from interface:PortableObjectRestore the contents of a user type instance by reading its state using the specified PofReader object.- Specified by:
readExternalin interfacePortableObject- Parameters:
in- the PofReader from which to read the object's state- Throws:
IOException- if an I/O error occurs
-
writeExternal
public void writeExternal(PofWriter out) throws IOException
Description copied from interface:PortableObjectSave the contents of a POF user type instance by writing its state using the specified PofWriter object.- Specified by:
writeExternalin interfacePortableObject- Parameters:
out- the PofWriter to which to write the object's state- Throws:
IOException- if an I/O error occurs
-
getParentSpanContext
protected com.tangosol.internal.tracing.SpanContext getParentSpanContext()
Return theSpanContextof the span that enqueued this task.- Returns:
- the
SpanContextof the span that enqueued this task - Since:
- 22.06
-
asyncEvaluateResult
protected boolean asyncEvaluateResult(Result<R> originalResult)
Evaluate the result of theTaskgiven the currentResults made by each of the assignedExecutor(s), returning if a result change occurred.- Parameters:
originalResult- the originalResultto evaluate- Returns:
trueif a new result is available,falseotherwise
-
asyncEvaluateExecutionStrategy
protected boolean asyncEvaluateExecutionStrategy(CacheService service, EnumSet<ExecutionStrategy.EvaluationRationale> rationales)
Asynchronously evaluate theExecutionStrategyfor theTaskand if necessary, update theExecutionPlanandResultmap.- Parameters:
service- theCacheServiceto use for accessingClusteredExecutorServicecachesrationales- theExecutionStrategy.EvaluationRationale- Returns:
trueif theExecutionPlanwas changed as part of evaluating,falseotherwise
-
cleanup
protected void cleanup(CacheService service, String sKey)
Cleanup metadata associated with the given task key.- Parameters:
service- the associatedCacheServicesKey- the task key
-
cleanProperties
protected void cleanProperties(CacheService service)
Clean up the task properties.- Parameters:
service- theCacheService
-
onInserted
public ComposableContinuation onInserted(CacheService service, InvocableMap.Entry entry, com.oracle.coherence.concurrent.executor.internal.Cause cause)
- Specified by:
onInsertedin interfacecom.oracle.coherence.concurrent.executor.internal.LiveObject- Parameters:
service- theCacheServicefor theLiveObjectentry- the entry being insertedcause- theCauseof theEvent- Returns:
- an optional
ComposableContinuationto be performed asynchronously for theLiveObject(may benull) - See Also:
onProcess(CacheService, Entry, Cause)
-
onUpdated
public ComposableContinuation onUpdated(CacheService service, InvocableMap.Entry entry, com.oracle.coherence.concurrent.executor.internal.Cause cause)
- Specified by:
onUpdatedin interfacecom.oracle.coherence.concurrent.executor.internal.LiveObject- Parameters:
service- theCacheServicefor theLiveObjectentry- the entry being updatedcause- theCauseof theEvent- Returns:
- an optional
ComposableContinuationto be performed asynchronously for theLiveObject(may benull) - See Also:
onProcess(CacheService, Entry, Cause)
-
onDeleted
public ComposableContinuation onDeleted(CacheService service, InvocableMap.Entry entry, com.oracle.coherence.concurrent.executor.internal.Cause cause)
Effectively, a no-op.- Specified by:
onDeletedin interfacecom.oracle.coherence.concurrent.executor.internal.LiveObject- Parameters:
service- theCacheServicefor theLiveObjectentry- the entry being deletedcause- theCauseof theEvent- Returns:
- an optional
ComposableContinuationto be performed asynchronously for theLiveObject(may benull)
-
-