Interface ActivityExecutionContext
-
- All Known Implementing Classes:
ActivityExecutionContextBase
public interface ActivityExecutionContext
Context object passed to an Activity implementation. UseActivity.getExecutionContext()
from an activity implementation to access.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
doNotCompleteOnReturn()
If this method is called during an Activity Execution then the Activity Execution is not going to complete when it's method returns.<V> java.util.Optional<V>
getHeartbeatDetails(java.lang.Class<V> detailsClass)
Extracts Heartbeat details from the last failed attempt.<V> java.util.Optional<V>
getHeartbeatDetails(java.lang.Class<V> detailsClass, java.lang.reflect.Type detailsGenericType)
Extracts Heartbeat details from the last failed attempt.ActivityInfo
getInfo()
Information about the Activity Execution and the Workflow Execution that invoked it.com.uber.m3.tally.Scope
getMetricsScope()
Get scope for reporting business metrics in activity logic.byte[]
getTaskToken()
Gets a correlation token that can be used to complete the Activity Execution asynchronously throughActivityCompletionClient.complete(byte[], Object)
.<V> void
heartbeat(V details)
Used to notify the Workflow Execution that the Activity Execution is alive.boolean
isDoNotCompleteOnReturn()
boolean
isUseLocalManualCompletion()
ManualActivityCompletionClient
useLocalManualCompletion()
For local manual completion, sets thedoNotCompleteOnReturn()
flag, making Activity Execution completion asynchronous, and returns the completion client.
-
-
-
Method Detail
-
getInfo
ActivityInfo getInfo()
Information about the Activity Execution and the Workflow Execution that invoked it.
-
heartbeat
<V> void heartbeat(V details) throws ActivityCompletionException
Used to notify the Workflow Execution that the Activity Execution is alive.- Parameters:
details
- In case the Activity Execution times out details are returned as a field of the exception that is thrown. The details are also accessible throughgetHeartbeatDetails(Class)
() on the next Activity Execution retry.- Throws:
ActivityCompletionException
- Which indicates that cancellation of the Activity Execution was requested by the Workflow Execution. Or it could indicate any other reason for an Activity Execution to stop. Should be rethrown from the Activity implementation to indicate a successful cancellation.
-
getHeartbeatDetails
<V> java.util.Optional<V> getHeartbeatDetails(java.lang.Class<V> detailsClass)
Extracts Heartbeat details from the last failed attempt. This is used in combination with retry options. An Activity Execution could be scheduled with optionalRetryOptions
viaActivityOptions
. If an Activity Execution failed then the server would attempt to dispatch another Activity Task to retry the execution according to the retry options. If there were Heartbeat details reported by the last Activity Execution that failed, they would be delivered along with the Activity Task for the next retry attempt and can be extracted by the Activity implementation.- Parameters:
detailsClass
- Class of the Heartbeat details
-
getHeartbeatDetails
<V> java.util.Optional<V> getHeartbeatDetails(java.lang.Class<V> detailsClass, java.lang.reflect.Type detailsGenericType)
Extracts Heartbeat details from the last failed attempt. This is used in combination with retry options. An Activity Execution could be scheduled with optionalRetryOptions
viaActivityOptions
. If an Activity Execution failed then the server would attempt to dispatch another Activity Task to retry the execution according to the retry options. If there were Heartbeat details reported by the last Activity Execution that failed, the details would be delivered along with the Activity Task for the next retry attempt. The Activity implementation can extract the details viagetHeartbeatDetails(Class)
() and resume progress.- Parameters:
detailsClass
- Class of the Heartbeat detailsdetailsGenericType
- Type of the Heartbeat details
-
getTaskToken
byte[] getTaskToken()
Gets a correlation token that can be used to complete the Activity Execution asynchronously throughActivityCompletionClient.complete(byte[], Object)
.
-
doNotCompleteOnReturn
void doNotCompleteOnReturn()
If this method is called during an Activity Execution then the Activity Execution is not going to complete when it's method returns. It is expected to be completed asynchronously usingActivityCompletionClient
.Async Activity Executions that have
isUseLocalManualCompletion()
set to false will not respect the limit defined byWorkerOptions.getMaxConcurrentActivityExecutionSize()
.If you want to maintain the workflow's limit on the total number of concurrent Activity Executions and if you always complete those Activity Executions within the same Java process, you may use
useLocalManualCompletion()
instead.
-
isDoNotCompleteOnReturn
boolean isDoNotCompleteOnReturn()
- Returns:
- true if
doNotCompleteOnReturn()
was called and supported by the activity type, false otherwise
-
isUseLocalManualCompletion
boolean isUseLocalManualCompletion()
- Returns:
- true if
useLocalManualCompletion()
method has been called on this context. If this flag is set to true,ActivityWorker
would not release concurrency semaphore and delegate release function to the manual Activity client returned byuseLocalManualCompletion()
-
useLocalManualCompletion
ManualActivityCompletionClient useLocalManualCompletion()
For local manual completion, sets thedoNotCompleteOnReturn()
flag, making Activity Execution completion asynchronous, and returns the completion client. Returned completion client must be used to complete the Activity Execution inside the same Java process.The completion client returned from this method updates the Worker's Active Activity Executions Counter. This way the limit of concurrent Activity Executions defined by
WorkerOptions.Builder.setMaxConcurrentActivityExecutionSize(int)
is respected. It's the main difference of this method from callingdoNotCompleteOnReturn()
.Always call one of the completion methods on the obtained completion client. Otherwise, an Activity Worker could stop polling as it will consider Activity Executions that wasn't explicitly completed as still running.
-
getMetricsScope
com.uber.m3.tally.Scope getMetricsScope()
Get scope for reporting business metrics in activity logic. This scope is tagged with a workflow and an activity type.The original metrics scope is set through
WorkflowServiceStubsOptions.Builder.setMetricsScope(Scope)
when a worker starts up.
-
-