Interface ThreadState
- All Superinterfaces:
LinkedListSetEntry<ThreadState,ProcessState>
- All Known Implementing Classes:
ThreadStateImpl
State of a thread within the ProcessState.
May be used as a LinkedListSetEntry in a list of ThreadState
instances for a ProcessState.
- Author:
- Daniel Sagenschneider
-
Method Summary
Modifier and TypeMethodDescriptionavoidTeam(FunctionState function, TeamManagement team) Runs avoiding the specifiedTeam.createFlow(FlowCompletion flowCompletion, EscalationCompletion escalationCompletion) Creates aFlowcontained in thisThreadState.flowComplete(Flow flow, Throwable flowEscalation, EscalationCompletion completion) Flags that the inputFlowhas completed.getGovernanceContainer(int index) Obtains theGovernanceContainerfor the input index.getManagedObjectContainer(int index) Obtains theManagedObjectContainerfor the input index.intObtains the maximumFunctionStatechain length for thisThreadState.Obtains theProcessStateof the process containing thisThreadState.handleEscalation(Throwable escalation, EscalationCompletion completion) booleanIndicates if thisThreadStateis attached to the currentThread.booleanisGovernanceActive(int index) Indicates if theGovernanceis active.booleanIndicates if changes to theThreadStateare safe on the currentThread.voidLocks thisThreadStateto currentThread.voidprofile(ManagedFunctionLogicMetaData functionMetaData) Profiles thatManagedObjectContaineris being executed.Obtains theFunctionStateto register theThreadProfiler.<R,T extends Throwable>
RrunProcessSafeOperation(ProcessSafeOperation<R, T> operation) Runs theProcessSafeOperation.<R,T extends Throwable>
RrunThreadSafeOperation(ThreadSafeOperation<R, T> operation) Run theThreadSafeOperation.runWithin(FunctionState function) Runs theFunctionStatewithin thisThreadState.then(FunctionState function, FunctionState thenFunction) CreatesFunctionStateto execute the chain of the firstFunctionStatebefore moving onto execute the chain of the secondFunctionState.Methods inherited from interface net.officefloor.frame.internal.structure.LinkedListSetEntry
getLinkedListSetOwner, getNext, getPrev, setNext, setPrev
-
Method Details
-
isAttachedToThread
boolean isAttachedToThread()Indicates if thisThreadStateis attached to the currentThread.- Returns:
trueifThreadStateis attached to the currentThread.
-
isThreadStateSafe
boolean isThreadStateSafe()Indicates if changes to theThreadStateare safe on the currentThread.- Returns:
trueshould changes to theThreadStatebe safe on the currentThread.
-
lockThreadState
Locks thisThreadStateto currentThread.- Throws:
IllegalStateException- IfThreadStatenot attached toThread.
-
then
CreatesFunctionStateto execute the chain of the firstFunctionStatebefore moving onto execute the chain of the secondFunctionState.- Parameters:
function- Head of initialFunctionStatechain to complete.thenFunction- Head of the secondFunctionStatechain to then complete next.- Returns:
FunctionStateto execute the chains one after another.
-
runWithin
Runs theFunctionStatewithin thisThreadState.- Parameters:
function-FunctionStateto run within thisThreadState.- Returns:
FunctionStaterunning within thisThreadState.
-
avoidTeam
Runs avoiding the specifiedTeam.- Parameters:
function-FunctionStateto avoid being executed by the specifiedTeam.team-TeamManagementofTeamto avoid.- Returns:
AvoidTeam.
-
getMaximumFunctionChainLength
int getMaximumFunctionChainLength()Obtains the maximum
FunctionStatechain length for thisThreadState.Once the
FunctionStatechain has reached this length, it will be broken. (spawned in anotherThread). This avoidsStackOverflowErrorissues inFunctionStatechain being too large.- Returns:
- Maximum
FunctionStatechain length for thisThreadState.
-
runThreadSafeOperation
Run the
ThreadSafeOperation.Initially locks are not taken to make the main
ThreadStatesafe. This ensures theThreadSafeOperationis run under critical section of thisThreadState.- Type Parameters:
R- Return type fromThreadSafeOperation.T- PossibleEscalationfromThreadSafeOperation.- Parameters:
operation-ThreadSafeOperation.- Returns:
- Optional return value from
ThreadSafeOperation. - Throws:
T- OptionalThrowablefromThreadSafeOperation.
-
runProcessSafeOperation
Runs theProcessSafeOperation.- Type Parameters:
R- Return type fromProcessSafeOperation.T- PossibleEscalationfromProcessSafeOperation.- Parameters:
operation-ProcessSafeOperation.- Returns:
- Optional return value from
ProcessSafeOperation. - Throws:
T- OptionalThrowablefromProcessSafeOperation.
-
createFlow
Creates aFlowcontained in thisThreadState.- Parameters:
flowCompletion- OptionalFlowCompletionto handle completion of theFlow. May benull.escalationCompletion- OptionalEscalationCompletionto handle completion ofFlowand notifyEscalationhandling complete. May benull.- Returns:
- New
Flow.
-
handleEscalation
- Parameters:
escalation-Escalation.completion- OptionalEscalationCompletionto be notified of completion ofEscalationhandling.- Returns:
FunctionStateto handle theEscalation.
-
flowComplete
Flags that the inputFlowhas completed.- Parameters:
flow-Flowthat has completed.flowEscalation- PossibleEscalationfrom theFlow. May benull.completion-EscalationCompletion. May benull.- Returns:
- Optional
FunctionStateto complete theFlow.
-
getProcessState
ProcessState getProcessState()Obtains theProcessStateof the process containing thisThreadState.- Returns:
ProcessStateof the process containing thisThreadState.
-
getManagedObjectContainer
Obtains theManagedObjectContainerfor the input index.- Parameters:
index- Index of theManagedObjectContainerto be returned.- Returns:
ManagedObjectContainerfor the index.
-
getGovernanceContainer
Obtains theGovernanceContainerfor the input index.- Parameters:
index- Index of theGovernanceContainerto be returned.- Returns:
GovernanceContainerfor the index only if active. If not active will returnnull.
-
isGovernanceActive
boolean isGovernanceActive(int index) Indicates if the
Governanceis active.This provides a quick check and avoids creation of the
GovernanceContainer.- Parameters:
index- Index of theGovernanceto check active.- Returns:
trueif theGovernanceis active.
-
registerThreadProfiler
FunctionState registerThreadProfiler()Obtains theFunctionStateto register theThreadProfiler.- Returns:
FunctionStateto register theThreadProfiler. May benullif noThreadProfilerrequired.
-
profile
Profiles thatManagedObjectContaineris being executed.- Parameters:
functionMetaData-ManagedFunctionLogicMetaDataof theManagedFunctionContainerbeing executed.
-