@InterfaceAudience.Private @InterfaceStability.Evolving public abstract class StateMachineProcedure<TEnvironment,TState> extends Procedure<TEnvironment>
Modifier and Type | Class and Description |
---|---|
protected static class |
StateMachineProcedure.Flow |
Modifier and Type | Field and Description |
---|---|
private int |
stateCount |
private int[] |
states |
Constructor and Description |
---|
StateMachineProcedure() |
Modifier and Type | Method and Description |
---|---|
protected void |
deserializeStateData(InputStream stream)
Called on store load to allow the user to decode the previously serialized
state.
|
protected Procedure[] |
execute(TEnvironment env)
The main code of the procedure.
|
protected abstract StateMachineProcedure.Flow |
executeFromState(TEnvironment env,
TState state)
called to perform a single step of the specified 'state' of the procedure
|
private TState |
getCurrentState() |
protected abstract TState |
getInitialState()
Return the initial state object that will be used for the first call to executeFromState().
|
protected abstract TState |
getState(int stateId)
Convert an ordinal (or state id) to an Enum (or more descriptive) state object.
|
protected abstract int |
getStateId(TState state)
Convert the Enum (or more descriptive) state object to an ordinal (or state id).
|
protected boolean |
isYieldAfterExecutionStep(TEnvironment env)
By default, the executor will try ro run procedures start to finish.
|
protected boolean |
isYieldBeforeExecuteFromState(TEnvironment env,
TState state)
By default, the executor will try ro run all the steps of the procedure start to finish.
|
protected void |
rollback(TEnvironment env)
The code to undo what done by the execute() code.
|
protected abstract void |
rollbackState(TEnvironment env,
TState state)
called to perform the rollback of the specified state
|
protected void |
serializeStateData(OutputStream stream)
The user-level code of the procedure may have some state to
persist (e.g.
|
private void |
setNextState(int stateId)
Set the next state for the procedure.
|
protected void |
setNextState(TState state)
Set the next state for the procedure.
|
protected void |
toStringState(StringBuilder builder)
Called from
Procedure.toString() when interpolating Procedure state |
abort, acquireLock, addStackIndex, beforeReplay, childrenCountDown, compareTo, completionCleanup, convert, convert, createProcedureInfo, doExecute, doRollback, elapsedTime, getException, getLastUpdate, getNonceKey, getOwner, getParentProcId, getProcId, getProcIdHashCode, getResult, getRootProcedureId, getStackIndexes, getStartTime, getState, getTimeout, getTimeRemaining, hasException, hasOwner, hasParent, hasTimeout, incChildrenLatch, isFailed, isFinished, isSuccess, isWaiting, newInstance, releaseLock, removeStackIndex, setAbortFailure, setChildrenLatch, setFailure, setFailure, setNonceKey, setOwner, setParentProcId, setProcId, setResult, setStackIndexes, setStartTime, setState, setTimeout, setTimeoutFailure, shouldWaitClientAck, toString, toStringClass, toStringClassDetails, toStringDetails, toStringSimpleSB, updateTimestamp, validateClass, wasExecuted
protected abstract StateMachineProcedure.Flow executeFromState(TEnvironment env, TState state) throws ProcedureYieldException, InterruptedException
state
- state to executeProcedureYieldException
InterruptedException
protected abstract void rollbackState(TEnvironment env, TState state) throws IOException, InterruptedException
state
- state to rollbackIOException
- temporary failure, the rollback will retry laterInterruptedException
protected abstract TState getState(int stateId)
stateId
- the ordinal() of the state enum (or state id)protected abstract int getStateId(TState state)
state
- the state enum objectprotected abstract TState getInitialState()
protected void setNextState(TState state)
state
- the state enum objectprotected boolean isYieldBeforeExecuteFromState(TEnvironment env, TState state)
state
- the state we are going to execute next.protected Procedure[] execute(TEnvironment env) throws ProcedureYieldException, InterruptedException
Procedure
execute
in class Procedure<TEnvironment>
env
- the environment passed to the ProcedureExecutorProcedureYieldException
- the procedure will be added back to the queue and retried laterInterruptedException
- the procedure will be added back to the queue and retried laterprotected void rollback(TEnvironment env) throws IOException, InterruptedException
Procedure
rollback
in class Procedure<TEnvironment>
env
- the environment passed to the ProcedureExecutorIOException
- temporary failure, the rollback will retry laterInterruptedException
- the procedure will be added back to the queue and retried laterprotected boolean isYieldAfterExecutionStep(TEnvironment env)
Procedure
isYieldAfterExecutionStep
in class Procedure<TEnvironment>
env
- the environment passed to the ProcedureExecutorprivate TState getCurrentState()
private void setNextState(int stateId)
stateId
- the ordinal() of the state enum (or state id)protected void toStringState(StringBuilder builder)
Procedure
Procedure.toString()
when interpolating Procedure
statetoStringState
in class Procedure<TEnvironment>
builder
- Append current ProcedureProtos.ProcedureState
protected void serializeStateData(OutputStream stream) throws IOException
Procedure
serializeStateData
in class Procedure<TEnvironment>
stream
- the stream that will contain the user serialized dataIOException
protected void deserializeStateData(InputStream stream) throws IOException
Procedure
deserializeStateData
in class Procedure<TEnvironment>
stream
- the stream that contains the user serialized dataIOException
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.