Class ActivityExecutionContextBase
- java.lang.Object
-
- io.temporal.common.interceptors.ActivityExecutionContextBase
-
- All Implemented Interfaces:
ActivityExecutionContext
public class ActivityExecutionContextBase extends java.lang.Object implements ActivityExecutionContext
Convenience class for implementing ActivityInterceptors.
-
-
Constructor Summary
Constructors Constructor Description ActivityExecutionContextBase(ActivityExecutionContext next)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddoNotCompleteOnReturn()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.ActivityInfogetInfo()Information about the Activity Execution and the Workflow Execution that invoked it.com.uber.m3.tally.ScopegetMetricsScope()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> voidheartbeat(V details)Used to notify the Workflow Execution that the Activity Execution is alive.booleanisDoNotCompleteOnReturn()booleanisUseLocalManualCompletion()ManualActivityCompletionClientuseLocalManualCompletion()For local manual completion, sets theActivityExecutionContext.doNotCompleteOnReturn()flag, making Activity Execution completion asynchronous, and returns the completion client.
-
-
-
Constructor Detail
-
ActivityExecutionContextBase
public ActivityExecutionContextBase(ActivityExecutionContext next)
-
-
Method Detail
-
getInfo
public ActivityInfo getInfo()
Description copied from interface:ActivityExecutionContextInformation about the Activity Execution and the Workflow Execution that invoked it.- Specified by:
getInfoin interfaceActivityExecutionContext
-
heartbeat
public <V> void heartbeat(V details) throws ActivityCompletionExceptionDescription copied from interface:ActivityExecutionContextUsed to notify the Workflow Execution that the Activity Execution is alive.- Specified by:
heartbeatin interfaceActivityExecutionContext- 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 throughActivityExecutionContext.getHeartbeatDetails(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
public <V> java.util.Optional<V> getHeartbeatDetails(java.lang.Class<V> detailsClass)
Description copied from interface:ActivityExecutionContextExtracts Heartbeat details from the last failed attempt. 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.- Specified by:
getHeartbeatDetailsin interfaceActivityExecutionContext- Parameters:
detailsClass- Class of the Heartbeat details
-
getHeartbeatDetails
public <V> java.util.Optional<V> getHeartbeatDetails(java.lang.Class<V> detailsClass, java.lang.reflect.Type detailsGenericType)Description copied from interface:ActivityExecutionContextExtracts Heartbeat details from the last failed attempt. 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, the details would be delivered along with the Activity Task for the next retry attempt. The Activity implementation can extract the details viaActivityExecutionContext.getHeartbeatDetails(Class)() and resume progress.- Specified by:
getHeartbeatDetailsin interfaceActivityExecutionContext- Parameters:
detailsClass- Class of the Heartbeat detailsdetailsGenericType- Type of the Heartbeat details
-
getTaskToken
public byte[] getTaskToken()
Description copied from interface:ActivityExecutionContextGets a correlation token that can be used to complete the Activity Execution asynchronously throughActivityCompletionClient.complete(byte[], Object).- Specified by:
getTaskTokenin interfaceActivityExecutionContext
-
doNotCompleteOnReturn
public void doNotCompleteOnReturn()
Description copied from interface:ActivityExecutionContextIf 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
ActivityExecutionContext.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
ActivityExecutionContext.useLocalManualCompletion()instead.- Specified by:
doNotCompleteOnReturnin interfaceActivityExecutionContext- See Also:
as a stricter version of this method respecting the worker's concurrent activities limit
-
isDoNotCompleteOnReturn
public boolean isDoNotCompleteOnReturn()
- Specified by:
isDoNotCompleteOnReturnin interfaceActivityExecutionContext- Returns:
- true if
ActivityExecutionContext.doNotCompleteOnReturn()was called and supported by the activity type, false otherwise
-
isUseLocalManualCompletion
public boolean isUseLocalManualCompletion()
- Specified by:
isUseLocalManualCompletionin interfaceActivityExecutionContext- Returns:
- true if
ActivityExecutionContext.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 byActivityExecutionContext.useLocalManualCompletion()
-
useLocalManualCompletion
public ManualActivityCompletionClient useLocalManualCompletion()
Description copied from interface:ActivityExecutionContextFor local manual completion, sets theActivityExecutionContext.doNotCompleteOnReturn()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 callingActivityExecutionContext.doNotCompleteOnReturn().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.
- Specified by:
useLocalManualCompletionin interfaceActivityExecutionContext
-
getMetricsScope
public com.uber.m3.tally.Scope getMetricsScope()
Description copied from interface:ActivityExecutionContextGet 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.- Specified by:
getMetricsScopein interfaceActivityExecutionContext
-
-