Class WorkflowStateMachines


  • public final class WorkflowStateMachines
    extends java.lang.Object
    • Method Detail

      • setStartedIds

        public void setStartedIds​(long previousStartedEventId,
                                  long workflowTaskStartedEventId)
        Parameters:
        previousStartedEventId - eventId of the last EVENT_TYPE_WORKFLOW_TASK_STARTED in history that was successfully finished.
        workflowTaskStartedEventId - eventId of the workflowTask that was picked up by a worker and triggered a replay or an execution
      • handleEvent

        public void handleEvent​(io.temporal.api.history.v1.HistoryEvent event,
                                boolean hasNextEvent)
        Handle a single event from the workflow history.
        Parameters:
        event - event from the history.
        hasNextEvent - false if this is the last event in the history.
      • takeCommands

        public java.util.List<io.temporal.api.command.v1.Command> takeCommands()
      • getLastStartedEventId

        public long getLastStartedEventId()
      • scheduleActivityTask

        public Functions.Proc scheduleActivityTask​(ExecuteActivityParameters attributes,
                                                   Functions.Proc2<java.util.Optional<io.temporal.api.common.v1.Payloads>,​io.temporal.api.failure.v1.Failure> callback)
        Parameters:
        attributes - attributes used to schedule an activity
        callback - completion callback
        Returns:
        an instance of ActivityCommands
      • newTimer

        public Functions.Proc newTimer​(io.temporal.api.command.v1.StartTimerCommandAttributes attributes,
                                       Functions.Proc1<io.temporal.api.history.v1.HistoryEvent> completionCallback)
        Creates a new timer state machine
        Parameters:
        attributes - timer command attributes
        completionCallback - invoked when timer fires or reports cancellation. One of TimerFiredEvent, TimerCanceledEvent.
        Returns:
        cancellation callback that should be invoked to initiate timer cancellation
      • startChildWorkflow

        public Functions.Proc startChildWorkflow​(StartChildWorkflowExecutionParameters parameters,
                                                 Functions.Proc1<io.temporal.api.common.v1.WorkflowExecution> startedCallback,
                                                 Functions.Proc2<java.util.Optional<io.temporal.api.common.v1.Payloads>,​java.lang.Exception> completionCallback)
        Creates a new child state machine
        Parameters:
        parameters - child workflow start command parameters.
        startedCallback - callback that is notified about child start
        completionCallback - invoked when child reports completion or failure.
        Returns:
        cancellation callback that should be invoked to cancel the child
      • signalExternalWorkflowExecution

        public Functions.Proc signalExternalWorkflowExecution​(io.temporal.api.command.v1.SignalExternalWorkflowExecutionCommandAttributes attributes,
                                                              Functions.Proc2<java.lang.Void,​io.temporal.api.failure.v1.Failure> completionCallback)
        Parameters:
        attributes -
        completionCallback - invoked when signal delivery completes of fails. The following types
      • requestCancelExternalWorkflowExecution

        public void requestCancelExternalWorkflowExecution​(io.temporal.api.command.v1.RequestCancelExternalWorkflowExecutionCommandAttributes attributes,
                                                           Functions.Proc2<java.lang.Void,​java.lang.RuntimeException> completionCallback)
        Parameters:
        attributes - attributes to use to cancel external workflow
        completionCallback - one of ExternalWorkflowExecutionCancelRequestedEvent,
      • upsertSearchAttributes

        public void upsertSearchAttributes​(io.temporal.api.common.v1.SearchAttributes attributes)
      • completeWorkflow

        public void completeWorkflow​(java.util.Optional<io.temporal.api.common.v1.Payloads> workflowOutput)
      • failWorkflow

        public void failWorkflow​(io.temporal.api.failure.v1.Failure failure)
      • cancelWorkflow

        public void cancelWorkflow()
      • continueAsNewWorkflow

        public void continueAsNewWorkflow​(io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes attributes)
      • isReplaying

        public boolean isReplaying()
      • currentTimeMillis

        public long currentTimeMillis()
      • randomUUID

        public java.util.UUID randomUUID()
      • newRandom

        public java.util.Random newRandom()
      • sideEffect

        public void sideEffect​(Functions.Func<java.util.Optional<io.temporal.api.common.v1.Payloads>> func,
                               Functions.Proc1<java.util.Optional<io.temporal.api.common.v1.Payloads>> callback)
      • mutableSideEffect

        public void mutableSideEffect​(java.lang.String id,
                                      Functions.Func1<java.util.Optional<io.temporal.api.common.v1.Payloads>,​java.util.Optional<io.temporal.api.common.v1.Payloads>> func,
                                      Functions.Proc1<java.util.Optional<io.temporal.api.common.v1.Payloads>> callback)
        Parameters:
        id - mutable side effect id
        func - given the value from the last marker returns value to store. If result is empty nothing is recorded into the history.
        callback - used to report result or failure
      • getVersion

        public void getVersion​(java.lang.String changeId,
                               int minSupported,
                               int maxSupported,
                               Functions.Proc2<java.lang.Integer,​java.lang.RuntimeException> callback)