@InterfaceAudience.Private @InterfaceStability.Evolving public abstract class Procedure<TEnvironment> extends Object implements Comparable<Procedure>
Constructor and Description |
---|
Procedure() |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
abort(TEnvironment env)
The abort() call is asynchronous and each procedure must decide how to deal
with that, if they want to be abortable.
|
protected boolean |
acquireLock(TEnvironment env)
The user should override this method, and try to take a lock if necessary.
|
protected void |
addStackIndex(int index)
Called by the RootProcedureState on procedure execution.
|
protected void |
beforeReplay(TEnvironment env)
Called when the procedure is loaded for replay.
|
protected boolean |
childrenCountDown()
Called by the ProcedureExecutor to notify that one of the sub-procedures
has completed.
|
int |
compareTo(Procedure other) |
protected void |
completionCleanup(TEnvironment env)
Called when the procedure is marked as completed (success or rollback).
|
static ProcedureProtos.Procedure |
convert(Procedure proc)
Helper to convert the procedure to protobuf.
|
static Procedure |
convert(ProcedureProtos.Procedure proto)
Helper to convert the protobuf procedure.
|
static ProcedureInfo |
createProcedureInfo(Procedure proc,
NonceKey nonceKey)
Helper to create the ProcedureInfo from Procedure.
|
protected abstract void |
deserializeStateData(InputStream stream)
Called on store load to allow the user to decode the previously serialized
state.
|
protected Procedure[] |
doExecute(TEnvironment env)
Internal method called by the ProcedureExecutor that starts the
user-level code execute().
|
protected void |
doRollback(TEnvironment env)
Internal method called by the ProcedureExecutor that starts the
user-level code rollback().
|
long |
elapsedTime() |
protected abstract Procedure[] |
execute(TEnvironment env)
The main code of the procedure.
|
RemoteProcedureException |
getException() |
long |
getLastUpdate() |
NonceKey |
getNonceKey() |
String |
getOwner() |
long |
getParentProcId() |
long |
getProcId() |
byte[] |
getResult() |
protected static Long |
getRootProcedureId(Map<Long,Procedure> procedures,
Procedure proc) |
protected int[] |
getStackIndexes() |
long |
getStartTime() |
protected ProcedureProtos.ProcedureState |
getState() |
int |
getTimeout() |
long |
getTimeRemaining() |
boolean |
hasException() |
boolean |
hasOwner() |
boolean |
hasParent() |
boolean |
hasTimeout() |
protected void |
incChildrenLatch()
Called by the ProcedureExecutor on procedure-load to restore the latch state
|
boolean |
isFailed() |
boolean |
isFinished() |
boolean |
isSuccess() |
boolean |
isWaiting() |
protected static Procedure |
newInstance(String className) |
protected void |
releaseLock(TEnvironment env)
The user should override this method, and release lock if necessary.
|
protected boolean |
removeStackIndex() |
protected abstract void |
rollback(TEnvironment env)
The code to undo what done by the execute() code.
|
protected abstract void |
serializeStateData(OutputStream stream)
The user-level code of the procedure may have some state to
persist (e.g.
|
protected void |
setAbortFailure(String source,
String msg) |
protected void |
setChildrenLatch(int numChildren)
Called by the ProcedureExecutor on procedure-load to restore the latch state
|
protected void |
setFailure(RemoteProcedureException exception) |
protected void |
setFailure(String source,
Throwable cause) |
protected void |
setNonceKey(NonceKey nonceKey)
Called by the ProcedureExecutor to set the value to the newly created procedure.
|
void |
setOwner(String owner) |
protected void |
setParentProcId(long parentProcId)
Called by the ProcedureExecutor to assign the parent to the newly created procedure.
|
protected void |
setProcId(long procId)
Called by the ProcedureExecutor to assign the ID to the newly created procedure.
|
protected void |
setResult(byte[] result)
The procedure may leave a "result" on completion.
|
protected void |
setStackIndexes(List<Integer> stackIndexes)
Called on store load to initialize the Procedure internals after
the creation/deserialization.
|
protected void |
setStartTime(long startTime)
Called on store load to initialize the Procedure internals after
the creation/deserialization.
|
protected void |
setState(ProcedureProtos.ProcedureState state) |
protected void |
setTimeout(int timeout) |
protected boolean |
setTimeoutFailure() |
String |
toString() |
protected String |
toStringClass() |
protected void |
toStringClassDetails(StringBuilder builder)
Extend the toString() information with the procedure details
e.g.
|
String |
toStringDetails()
Extend the toString() information with more procedure
details
|
protected StringBuilder |
toStringSimpleSB()
Build the StringBuilder for the simple form of
procedure string.
|
protected void |
updateTimestamp() |
protected static void |
validateClass(Procedure proc) |
protected boolean |
wasExecuted() |
protected abstract Procedure[] execute(TEnvironment env) throws ProcedureYieldException
ProcedureYieldException
protected abstract void rollback(TEnvironment env) throws IOException
IOException
- temporary failure, the rollback will retry laterprotected abstract boolean abort(TEnvironment env)
protected abstract void serializeStateData(OutputStream stream) throws IOException
stream
- the stream that will contain the user serialized dataIOException
protected abstract void deserializeStateData(InputStream stream) throws IOException
stream
- the stream that contains the user serialized dataIOException
protected boolean acquireLock(TEnvironment env)
protected void releaseLock(TEnvironment env)
protected void beforeReplay(TEnvironment env)
protected void completionCleanup(TEnvironment env)
protected StringBuilder toStringSimpleSB()
public String toStringDetails()
protected String toStringClass()
protected void toStringClassDetails(StringBuilder builder)
builder
- the string builder to use to append the proc specific informationpublic byte[] getResult()
protected void setResult(byte[] result)
result
- the serialized result that will be passed to the clientpublic long getProcId()
public boolean hasParent()
public boolean hasException()
public boolean hasTimeout()
public long getParentProcId()
public NonceKey getNonceKey()
public boolean isFailed()
public boolean isSuccess()
public boolean isFinished()
public boolean isWaiting()
public RemoteProcedureException getException()
public long getStartTime()
public long getLastUpdate()
public long elapsedTime()
protected void setTimeout(int timeout)
timeout
- timeout in msecpublic int getTimeout()
public long getTimeRemaining()
@InterfaceAudience.Private public void setOwner(String owner)
public String getOwner()
public boolean hasOwner()
@InterfaceAudience.Private protected void setState(ProcedureProtos.ProcedureState state)
@InterfaceAudience.Private protected ProcedureProtos.ProcedureState getState()
protected void setFailure(RemoteProcedureException exception)
@InterfaceAudience.Private protected boolean setTimeoutFailure()
@InterfaceAudience.Private protected void setProcId(long procId)
@InterfaceAudience.Private protected void setParentProcId(long parentProcId)
@InterfaceAudience.Private protected void setNonceKey(NonceKey nonceKey)
@InterfaceAudience.Private protected Procedure[] doExecute(TEnvironment env) throws ProcedureYieldException
ProcedureYieldException
@InterfaceAudience.Private protected void doRollback(TEnvironment env) throws IOException
IOException
@InterfaceAudience.Private protected void setStartTime(long startTime)
protected void updateTimestamp()
@InterfaceAudience.Private protected void setChildrenLatch(int numChildren)
@InterfaceAudience.Private protected void incChildrenLatch()
@InterfaceAudience.Private protected boolean childrenCountDown()
@InterfaceAudience.Private protected void addStackIndex(int index)
@InterfaceAudience.Private protected boolean removeStackIndex()
@InterfaceAudience.Private protected void setStackIndexes(List<Integer> stackIndexes)
@InterfaceAudience.Private protected boolean wasExecuted()
@InterfaceAudience.Private protected int[] getStackIndexes()
public int compareTo(Procedure other)
compareTo
in interface Comparable<Procedure>
@InterfaceAudience.Private protected static Long getRootProcedureId(Map<Long,Procedure> procedures, Procedure proc)
protected static Procedure newInstance(String className) throws IOException
IOException
protected static void validateClass(Procedure proc) throws IOException
IOException
@InterfaceAudience.Private public static ProcedureInfo createProcedureInfo(Procedure proc, NonceKey nonceKey)
@InterfaceAudience.Private public static ProcedureProtos.Procedure convert(Procedure proc) throws IOException
IOException
@InterfaceAudience.Private public static Procedure convert(ProcedureProtos.Procedure proto) throws IOException
IOException
Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.