Package io.temporal.common.interceptors
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 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 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:ActivityExecutionContext
Information about the Activity Execution and the Workflow Execution that invoked it.- Specified by:
getInfo
in interfaceActivityExecutionContext
-
heartbeat
public <V> void heartbeat(V details) throws ActivityCompletionException
Description copied from interface:ActivityExecutionContext
Used to notify the Workflow Execution that the Activity Execution is alive.- Specified by:
heartbeat
in 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:ActivityExecutionContext
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.- Specified by:
getHeartbeatDetails
in 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:ActivityExecutionContext
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 viaActivityExecutionContext.getHeartbeatDetails(Class)
() and resume progress.- Specified by:
getHeartbeatDetails
in interfaceActivityExecutionContext
- Parameters:
detailsClass
- Class of the Heartbeat detailsdetailsGenericType
- Type of the Heartbeat details
-
getTaskToken
public byte[] getTaskToken()
Description copied from interface:ActivityExecutionContext
Gets a correlation token that can be used to complete the Activity Execution asynchronously throughActivityCompletionClient.complete(byte[], Object)
.- Specified by:
getTaskToken
in interfaceActivityExecutionContext
-
doNotCompleteOnReturn
public void doNotCompleteOnReturn()
Description copied from interface:ActivityExecutionContext
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 haveActivityExecutionContext.isUseLocalManualCompletion()
set to false would not respect the limit defined byWorkerOptions.getMaxConcurrentActivityExecutionSize()
. If you want to limit the number of concurrent async Activity Executions and if you always complete those Activity Executions with the same Activity Worker you should useActivityExecutionContext.useLocalManualCompletion()
instead.- Specified by:
doNotCompleteOnReturn
in interfaceActivityExecutionContext
-
isDoNotCompleteOnReturn
public boolean isDoNotCompleteOnReturn()
- Specified by:
isDoNotCompleteOnReturn
in interfaceActivityExecutionContext
- Returns:
- true if
ActivityExecutionContext.doNotCompleteOnReturn()
was called and supported by the activity type, false otherwise
-
isUseLocalManualCompletion
public boolean isUseLocalManualCompletion()
- Specified by:
isUseLocalManualCompletion
in interfaceActivityExecutionContext
- Returns:
- true if
ActivityExecutionContext.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 byActivityExecutionContext.useLocalManualCompletion()
-
useLocalManualCompletion
public ManualActivityCompletionClient useLocalManualCompletion()
Description copied from interface:ActivityExecutionContext
For 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 on the same machine. The main difference from callingActivityExecutionContext.doNotCompleteOnReturn()
directly is that by using this method the maximum number of concurrent Activity Executions defined byWorkerOptions.getMaxConcurrentActivityExecutionSize()
will be respected. Users must be careful and always call the completion method on theManualActivityCompletionClient
otherwise the Activity Worker could stop polling as it will consider all Activity Executions, that didn't explicitly finish, as still running.- Specified by:
useLocalManualCompletion
in interfaceActivityExecutionContext
-
getMetricsScope
public com.uber.m3.tally.Scope getMetricsScope()
Description copied from interface:ActivityExecutionContext
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.- Specified by:
getMetricsScope
in interfaceActivityExecutionContext
-
-