类 StateMachineProcedure<Env,TState>
- java.lang.Object
-
- org.apache.iotdb.confignode.procedure.Procedure<Env>
-
- org.apache.iotdb.confignode.procedure.impl.statemachine.StateMachineProcedure<Env,TState>
-
- 所有已实现的接口:
java.lang.Comparable<Procedure<Env>>
- 直接已知子类:
AbstractNodeProcedure,CreatePipeProcedure,CreateRegionGroupsProcedure,DeactivateTemplateProcedure,DeleteStorageGroupProcedure,DeleteTimeSeriesProcedure,DropPipeProcedure,RegionMigrateProcedure,StartPipeProcedure,StopPipeProcedure,UnsetTemplateProcedure
public abstract class StateMachineProcedure<Env,TState> extends Procedure<Env>
Procedure described by a series of steps.The procedure implementor must have an enum of 'states', describing the various step of the procedure. Once the procedure is running, the procedure-framework will call executeFromState() using the 'state' provided by the user. The first call to executeFromState() will be performed with 'state = null'. The implementor can jump between states using setNextState(MyStateEnum.ordinal()). The rollback will call rollbackState() for each state that was executed, in reverse order.
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classStateMachineProcedure.Flow
-
字段概要
字段 修饰符和类型 字段 说明 protected intstateCount-
从类继承的字段 org.apache.iotdb.confignode.procedure.Procedure
NO_PROC_ID, NO_TIMEOUT
-
-
构造器概要
构造器 构造器 说明 StateMachineProcedure()
-
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected booleanabort(Env env)The abort() call is asynchronous and each procedure must decide how to deal with it, if they want to be abortable.protected <T extends Procedure<Env>>
voidaddChildProcedure(T... subProcedure)Add a child procedure to executevoiddeserialize(java.nio.ByteBuffer byteBuffer)protected Procedure[]execute(Env env)The main code of the procedure.protected abstract StateMachineProcedure.FlowexecuteFromState(Env env, TState state)called to perform a single step of the specified 'state' of the procedureprotected voidfailIfAborted()If procedure has more states then abort it otherwise procedure is finished and abort can be ignored.protected TStategetCurrentState()intgetCurrentStateId()This method is used from test code as it cannot be assumed that state transition will happen sequentially.protected intgetCycles()protected abstract TStategetInitialState()Return the initial state object that will be used for the first call to executeFromState().protected abstract TStategetState(int stateId)Convert an ordinal (or state id) to an Enum (or more descriptive) state object.protected abstract intgetStateId(TState state)Convert the Enum (or more descriptive) state object to an ordinal (or state id).protected booleanisEofState()protected booleanisRollbackSupported(TState state)Used by the default implementation of abort() to know if the current state can be aborted and rollback can be triggered.protected booleanisYieldAfterExecution(Env env)To make executor yield between each execution step to give other procedures a chance to run.protected booleanisYieldBeforeExecuteFromState(Env env, TState state)By default, the executor will try ro run all the steps of the procedure start to finish.protected voidrollback(Env env)The code to undo what was done by the execute() code.protected abstract voidrollbackState(Env env, TState state)called to perform the rollback of the specified statevoidserialize(java.io.DataOutputStream stream)protected voidsetNextState(TState state)Set the next state for the procedure.protected voidtoStringState(java.lang.StringBuilder builder)Called fromProcedure.toString()when interpolatingProcedureState.-
从类继承的方法 org.apache.iotdb.confignode.procedure.Procedure
acquireLock, addStackIndex, afterRecover, beforeRecover, compareTo, completionCleanup, deserializeTypeInfo, doAcquireLock, doExecute, doReleaseLock, doRollback, elapsedTime, getChildrenLatch, getException, getLastUpdate, getParentProcId, getProcId, getProcName, getResult, getRootProcedureId, getRootProcId, getStackIndexes, getState, getSubmittedTime, getTimeout, getTimeoutTimestamp, hasChildren, hasException, hasLock, hasParent, hasTimeout, haveSameParent, holdLock, incChildrenLatch, isFailed, isFinished, isInitializing, isLockedWhenLoading, isRunnable, isSuccess, isWaiting, needPersistance, newInstance, releaseLock, removeStackIndex, resetPersistance, restoreLock, setAbortFailure, setChildrenLatch, setFailure, setFailure, setLastUpdate, setParentProcId, setProcId, setProcRunnable, setResult, setRootProcedureId, setRootProcId, setStackIndexes, setState, setSubmittedTime, setTimeout, setTimeoutFailure, skipPersistance, toString, toStringClass, toStringClassDetails, toStringDetails, toStringSimpleSB, updateTimestamp, waitInitialized, wasExecuted
-
-
-
-
方法详细资料
-
getCycles
protected final int getCycles()
-
executeFromState
protected abstract StateMachineProcedure.Flow executeFromState(Env env, TState state) throws ProcedureSuspendedException, ProcedureYieldException, java.lang.InterruptedException
called to perform a single step of the specified 'state' of the procedure- 参数:
state- state to execute- 返回:
- Flow.NO_MORE_STATE if the procedure is completed, Flow.HAS_MORE_STATE if there is another step.
- 抛出:
ProcedureSuspendedExceptionProcedureYieldExceptionjava.lang.InterruptedException
-
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 laterjava.lang.InterruptedExceptionProcedureException
-
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
从类复制的说明:ProcedureThe 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
从类复制的说明:ProcedureThe 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 laterjava.lang.InterruptedException- the procedure will be added back to the queue and retried laterProcedureException
-
isEofState
protected boolean isEofState()
-
abort
protected boolean abort(Env env)
从类复制的说明:ProcedureThe 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.
-
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)
从类复制的说明:ProcedureTo 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.
-
toStringState
protected void toStringState(java.lang.StringBuilder builder)
从类复制的说明:ProcedureCalled fromProcedure.toString()when interpolatingProcedureState. Allows decorating generic Procedure State with Procedure particulars.- 覆盖:
toStringState在类中Procedure<Env>- 参数:
builder- Append currentProcedureState
-
serialize
public void serialize(java.io.DataOutputStream stream) throws java.io.IOException
-
deserialize
public void deserialize(java.nio.ByteBuffer byteBuffer)
- 覆盖:
deserialize在类中Procedure<Env>
-
-