Interface DecisionContext

  • All Superinterfaces:
    ReplayAware

    public interface DecisionContext
    extends ReplayAware
    Represents the context for decider. Should only be used within the scope of workflow definition code, meaning any code which is not part of activity implementations.
    • Method Detail

      • isCancelRequested

        boolean isCancelRequested()
      • getExecutionStartToCloseTimeoutSeconds

        int getExecutionStartToCloseTimeoutSeconds()
      • getTaskList

        java.lang.String getTaskList()
      • getDomain

        java.lang.String getDomain()
      • getWorkflowId

        java.lang.String getWorkflowId()
      • getRunId

        java.lang.String getRunId()
      • getExecutionStartToCloseTimeout

        java.time.Duration getExecutionStartToCloseTimeout()
      • getDecisionTaskTimeout

        java.time.Duration getDecisionTaskTimeout()
      • getSearchAttributes

        SearchAttributes getSearchAttributes()
        Used to retrieve search attributes.
        Returns:
        SearchAttribute object which can be used by WorkflowUtils.getValueFromSearchAttributes to retrieve concrete value.
      • getContextPropagators

        java.util.List<ContextPropagator> getContextPropagators()
        Returns the set of configured context propagators
      • scheduleActivityTask

        java.util.function.Consumer<java.lang.Exception> scheduleActivityTask​(ExecuteActivityParameters parameters,
                                                                              java.util.function.BiConsumer<byte[],​java.lang.Exception> callback)
        Used to dynamically schedule an activity for execution
        Parameters:
        parameters - An object which encapsulates all the information required to schedule an activity for execution
        callback - Callback that is called upon activity completion or failure.
        Returns:
        cancellation handle. Invoke Consumer.accept(Object) to cancel activity task.
      • scheduleLocalActivityTask

        java.util.function.Consumer<java.lang.Exception> scheduleLocalActivityTask​(ExecuteLocalActivityParameters parameters,
                                                                                   java.util.function.BiConsumer<byte[],​java.lang.Exception> callback)
      • startChildWorkflow

        java.util.function.Consumer<java.lang.Exception> startChildWorkflow​(StartChildWorkflowExecutionParameters parameters,
                                                                            java.util.function.Consumer<WorkflowExecution> executionCallback,
                                                                            java.util.function.BiConsumer<byte[],​java.lang.Exception> callback)
        Start child workflow.
        Parameters:
        parameters - An object which encapsulates all the information required to schedule a child workflow for execution
        callback - Callback that is called upon child workflow completion or failure.
        Returns:
        cancellation handle. Invoke Consumer.accept(Object) to cancel activity task.
      • isServerSideChildWorkflowRetry

        boolean isServerSideChildWorkflowRetry()
        Is the next event in the history is child workflow initiated event and it has an attached retry policy. Used for backwards compatibility with the code that used local workflow retry when RetryOptions were specified.
      • isServerSideActivityRetry

        boolean isServerSideActivityRetry()
        Is the next event in the history is an activity scheduled event and it has an attached retry policy. Used for the backwards compatibility with the code that used local activity retry when RetryOptions were specified.
      • signalWorkflowExecution

        java.util.function.Consumer<java.lang.Exception> signalWorkflowExecution​(SignalExternalWorkflowParameters signalParameters,
                                                                                 java.util.function.BiConsumer<java.lang.Void,​java.lang.Exception> callback)
      • requestCancelWorkflowExecution

        Promise<java.lang.Void> requestCancelWorkflowExecution​(WorkflowExecution execution)
      • mutableSideEffect

        java.util.Optional<byte[]> mutableSideEffect​(java.lang.String id,
                                                     DataConverter dataConverter,
                                                     Functions.Func1<java.util.Optional<byte[]>,​java.util.Optional<byte[]>> func)
      • currentTimeMillis

        long currentTimeMillis()
        Returns:
        time of the PollForDecisionTaskResponse start event of the decision being processed or replayed.
      • createTimer

        java.util.function.Consumer<java.lang.Exception> createTimer​(long delaySeconds,
                                                                     java.util.function.Consumer<java.lang.Exception> callback)
        Create a Value that becomes ready after the specified delay.
        Parameters:
        delaySeconds - time-interval after which the Value becomes ready in seconds.
        callback - Callback that is called with null parameter after the specified delay. CancellationException is passed as a parameter in case of a cancellation.
        Returns:
        cancellation handle. Invoke Consumer.accept(Object) to cancel timer.
      • sideEffect

        byte[] sideEffect​(Functions.Func<byte[]> func)
        Executes the provided function once, records its result into the workflow history. The recorded result on history will be returned without executing the provided function during replay. This guarantees the deterministic requirement for workflow as the exact same result will be returned in replay. Common use case is to run some short non-deterministic code in workflow, like getting random number or new UUID. The only way to fail SideEffect is to throw Error which causes decision task failure. The decision task after timeout is rescheduled and re-executed giving SideEffect another chance to succeed.
        Parameters:
        func - function that is called once to return a value.
        Returns:
        value of the side effect.
      • getVersion

        int getVersion​(java.lang.String changeID,
                       DataConverter dataConverter,
                       int minSupported,
                       int maxSupported)
        GetVersion is used to safely perform backwards incompatible changes to workflow definitions. It is not allowed to update workflow code while there are workflows running as it is going to break determinism. The solution is to have both old code that is used to replay existing workflows as well as the new one that is used when it is executed for the first time. GetVersion returns maxSupported version when executed for the first time. This version is recorded into the workflow history as a marker event. Even if maxSupported version is changed the version that was recorded is returned on replay. DefaultVersion constant contains version of code that wasn't versioned before.
        Parameters:
        changeID - identifier of a particular change
        minSupported - min version supported for the change
        maxSupported - max version supported for the change
        Returns:
        version
      • newRandom

        java.util.Random newRandom()
      • getMetricsScope

        com.uber.m3.tally.Scope getMetricsScope()
        Returns:
        scope to be used for metrics reporting.
      • getEnableLoggingInReplay

        boolean getEnableLoggingInReplay()
        Returns:
        whether we do logging during decision replay.
      • randomUUID

        java.util.UUID randomUUID()
        Returns:
        replay safe UUID
      • upsertSearchAttributes

        void upsertSearchAttributes​(SearchAttributes searchAttributes)