Class WorkflowStateMachines


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

      • WorkflowStateMachines

        public WorkflowStateMachines​(StatesMachinesCallback callbacks,
                                     io.temporal.api.workflowservice.v1.GetSystemInfoResponse.Capabilities capabilities)
      • WorkflowStateMachines

        public WorkflowStateMachines​(StatesMachinesCallback callbacks,
                                     Functions.Proc1<io.temporal.internal.statemachines.StateMachine> stateMachineSink,
                                     io.temporal.api.workflowservice.v1.GetSystemInfoResponse.Capabilities capabilities)
    • Method Detail

      • setWorklfowStartedEventId

        public void setWorklfowStartedEventId​(long workflowTaskStartedEventId)
        Parameters:
        workflowTaskStartedEventId - eventId of the workflowTask that was picked up by a worker and triggered an execution. Used in WorkflowTaskStateMachine only to understand that this workflow task will not have a matching closing event and needs to be executed.
      • setLastWFTStartedEventId

        public void setLastWFTStartedEventId​(long eventId)
      • getLastWFTStartedEventId

        public long getLastWFTStartedEventId()
      • getCurrentWFTStartedEventId

        public long getCurrentWFTStartedEventId()
      • getHistorySize

        public long getHistorySize()
      • getCurrentTaskBuildId

        @Nullable
        public java.lang.String getCurrentTaskBuildId()
      • isContinueAsNewSuggested

        public boolean isContinueAsNewSuggested()
      • setReplaying

        public void setReplaying​(boolean replaying)
      • setMessages

        public void setMessages​(java.util.List<io.temporal.api.protocol.v1.Message> messages)
      • 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()
      • sendMessage

        public void sendMessage​(io.temporal.api.protocol.v1.Message message)
      • takeMessages

        public java.util.List<io.temporal.api.protocol.v1.Message> takeMessages()
      • tryUseSdkFlag

        public boolean tryUseSdkFlag​(SdkFlag flag)
        Returns:
        True if the SDK flag is supported in this workflow execution
      • takeNewSdkFlags

        public java.util.EnumSet<SdkFlag> takeNewSdkFlags()
        Returns:
        Set of all new flags set since the last call
      • 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.Proc2<io.temporal.api.common.v1.WorkflowExecution,​java.lang.Exception> 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 boolean getVersion​(java.lang.String changeId,
                                  int minSupported,
                                  int maxSupported,
                                  Functions.Proc2<java.lang.Integer,​java.lang.RuntimeException> callback)
      • handleLocalActivityCompletion

        public void handleLocalActivityCompletion​(LocalActivityResult laCompletion)