类 StateMachineProcedure<Env,​TState>

    • 字段详细资料

      • stateCount

        protected int stateCount
    • 构造器详细资料

      • StateMachineProcedure

        public StateMachineProcedure()
    • 方法详细资料

      • getCycles

        protected final int getCycles()
      • rollbackState

        protected abstract void rollbackState​(Env env,
                                              TState state)
                                       throws java.io.IOException,
                                              java.lang.InterruptedException,
                                              ProcedureException
        called to perform the rollback of the specified state
        参数:
        state - state to rollback
        抛出:
        java.io.IOException - temporary failure, the rollback will retry later
        java.lang.InterruptedException
        ProcedureException
      • getState

        protected abstract TState getState​(int stateId)
        Convert an ordinal (or state id) to an Enum (or more descriptive) state object.
        参数:
        stateId - the ordinal() of the state enum (or state id)
        返回:
        the state enum object
      • getStateId

        protected abstract int getStateId​(TState state)
        Convert the Enum (or more descriptive) state object to an ordinal (or state id).
        参数:
        state - the state enum object
        返回:
        stateId the ordinal() of the state enum (or state id)
      • getInitialState

        protected abstract TState getInitialState()
        Return the initial state object that will be used for the first call to executeFromState().
        返回:
        the initial state enum object
      • setNextState

        protected void setNextState​(TState state)
        Set the next state for the procedure.
        参数:
        state - the state enum object
      • isYieldBeforeExecuteFromState

        protected boolean isYieldBeforeExecuteFromState​(Env env,
                                                        TState state)
        By default, the executor will try ro run all the steps of the procedure start to finish. Return true to make the executor yield between execution steps to give other procedures time to run their steps.
        参数:
        state - the state we are going to execute next.
        返回:
        Return true if the executor should yield before the execution of the specified step. Defaults to return false.
      • addChildProcedure

        protected <T extends Procedure<Env>> void addChildProcedure​(T... subProcedure)
        Add a child procedure to execute
        参数:
        subProcedure - the child procedure
      • execute

        protected Procedure[] execute​(Env env)
                               throws ProcedureSuspendedException,
                                      ProcedureYieldException,
                                      java.lang.InterruptedException
        从类复制的说明: Procedure
        The main code of the procedure. It must be idempotent since execute() may be called multiple times in case of machine failure in the middle of the execution.
        指定者:
        execute 在类中 Procedure<Env>
        参数:
        env - the environment passed to the ProcedureExecutor
        返回:
        a set of sub-procedures to run or ourselves if there is more work to do or null if the procedure is done.
        抛出:
        ProcedureSuspendedException - Signal to the executor that Procedure has suspended itself and has set itself up waiting for an external event to wake it back up again.
        ProcedureYieldException - the procedure will be added back to the queue and retried later.
        java.lang.InterruptedException - the procedure will be added back to the queue and retried later.
      • rollback

        protected void rollback​(Env env)
                         throws java.io.IOException,
                                java.lang.InterruptedException,
                                ProcedureException
        从类复制的说明: Procedure
        The code to undo what was done by the execute() code. It is called when the procedure or one of the sub-procedures failed or an abort was requested. It should cleanup all the resources created by the execute() call. The implementation must be idempotent since rollback() may be called multiple time in case of machine failure in the middle of the execution.
        指定者:
        rollback 在类中 Procedure<Env>
        参数:
        env - the environment passed to the ProcedureExecutor
        抛出:
        java.io.IOException - temporary failure, the rollback will retry later
        java.lang.InterruptedException - the procedure will be added back to the queue and retried later
        ProcedureException
      • isEofState

        protected boolean isEofState()
      • abort

        protected boolean abort​(Env env)
        从类复制的说明: Procedure
        The abort() call is asynchronous and each procedure must decide how to deal with it, if they want to be abortable. The simplest implementation is to have an AtomicBoolean set in the abort() method and then the execute() will check if the abort flag is set or not. abort() may be called multiple times from the client, so the implementation must be idempotent.

        NOTE: abort() is not like Thread.interrupt(). It is just a notification that allows the procedure implementor abort.

        指定者:
        abort 在类中 Procedure<Env>
      • failIfAborted

        protected final void failIfAborted()
        If procedure has more states then abort it otherwise procedure is finished and abort can be ignored.
      • isRollbackSupported

        protected boolean isRollbackSupported​(TState state)
        Used by the default implementation of abort() to know if the current state can be aborted and rollback can be triggered.
      • isYieldAfterExecution

        protected boolean isYieldAfterExecution​(Env env)
        从类复制的说明: Procedure
        To make executor yield between each execution step to give other procedures a chance to run.
        覆盖:
        isYieldAfterExecution 在类中 Procedure<Env>
        参数:
        env - environment
        返回:
        return true if yield is allowed.
      • getCurrentState

        protected TState getCurrentState()
      • getCurrentStateId

        public int getCurrentStateId()
        This method is used from test code as it cannot be assumed that state transition will happen sequentially. Some procedures may skip steps/ states, some may add intermediate steps in future.
      • serialize

        public void serialize​(java.io.DataOutputStream stream)
                       throws java.io.IOException
        覆盖:
        serialize 在类中 Procedure<Env>
        抛出:
        java.io.IOException
      • deserialize

        public void deserialize​(java.nio.ByteBuffer byteBuffer)
        覆盖:
        deserialize 在类中 Procedure<Env>