Interface ActivityExecutionContext
- All Known Subinterfaces:
InternalActivityExecutionContext
- All Known Implementing Classes:
ActivityExecutionContextBase
Activity.getExecutionContext()
from an activity implementation to access.-
Method Summary
Modifier and TypeMethodDescriptionvoidIf this method is called during an Activity Execution then the Activity Execution is not going to complete when its method returns.Returns a token that can be used by Activity code to observe cancellation requests without recording Heartbeats.<V> Optional<V> getHeartbeatDetails(Class<V> detailsClass) Extracts Heartbeat details from the last heartbeat of this Activity Execution attempt.<V> Optional<V> getHeartbeatDetails(Class<V> detailsClass, Type detailsGenericType) Extracts Heartbeat details from the last heartbeat of this Activity Execution attempt.getInfo()Information about the Activity Execution and the Workflow Execution that invoked it.Get the currently running activity instance.<V> Optional<V> getLastHeartbeatDetails(Class<V> detailsClass) Returns details from the last failed attempt of this Activity Execution.<V> Optional<V> getLastHeartbeatDetails(Class<V> detailsClass, Type detailsGenericType) Returns details from the last failed attempt of this Activity Execution.com.uber.m3.tally.ScopeGet scope for reporting business metrics in activity logic.byte[]Gets a correlation token that can be used to complete the Activity Execution asynchronously throughActivityCompletionClient.complete(byte[], Object).Get aWorkflowClientthat can be used to start interact with the Temporal service from an activity.<V> voidheartbeat(V details) Used to notify the Workflow Execution that the Activity Execution is alive.booleanbooleanFor local manual completion, sets thedoNotCompleteOnReturn()flag, making Activity Execution completion asynchronous, and returns the completion client.
-
Method Details
-
getInfo
ActivityInfo getInfo()Information about the Activity Execution and the Workflow Execution that invoked it. -
heartbeat
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
Extracts Heartbeat details from the last heartbeat of this Activity Execution attempt. If there were no heartbeats in this attempt, details from the last failed attempt are returned instead. This is used in combination with retry options. An Activity Execution could be scheduled with optionalRetryOptionsviaActivityOptions. 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
Extracts Heartbeat details from the last heartbeat of this Activity Execution attempt. If there were no heartbeats in this attempt, details from the last failed attempt are returned instead. It is useful in combination with retry options. An Activity Execution could be scheduled with optionalRetryOptionsviaActivityOptions. 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
-
getLastHeartbeatDetails
Returns details from the last failed attempt of this Activity Execution. UnlikegetHeartbeatDetails(Class), the returned details are not updated on every heartbeat call within the current attempt.- Parameters:
detailsClass- Class of the Heartbeat details
-
getLastHeartbeatDetails
Returns details from the last failed attempt of this Activity Execution. UnlikegetHeartbeatDetails(Class, Type), the returned details are not updated on every heartbeat call within the current attempt.- 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). -
getCancellationToken
Returns a token that can be used by Activity code to observe cancellation requests without recording Heartbeats. -
doNotCompleteOnReturn
void doNotCompleteOnReturn()If this method is called during an Activity Execution then the Activity Execution is not going to complete when its 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.- See Also:
-
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,ActivityWorkerwould 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
ServiceStubsOptions.Builder.setMetricsScope(Scope)when a worker starts up. -
getWorkflowClient
WorkflowClient getWorkflowClient()Get aWorkflowClientthat can be used to start interact with the Temporal service from an activity. -
getInstance
Object getInstance()Get the currently running activity instance.
-