Interface ThreadState
-
- All Superinterfaces:
LinkedListSetEntry<ThreadState,ProcessState>
- All Known Implementing Classes:
ThreadStateImpl
public interface ThreadState extends LinkedListSetEntry<ThreadState,ProcessState>
State of a thread within the
ProcessState
.May be used as a
LinkedListSetEntry
in a list ofThreadState
instances for aProcessState
.- Author:
- Daniel Sagenschneider
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description AvoidTeam
avoidTeam(FunctionState function, TeamManagement team)
Runs avoiding the specifiedTeam
.Flow
createFlow(FlowCompletion flowCompletion, EscalationCompletion escalationCompletion)
Creates aFlow
contained in thisThreadState
.FunctionState
flowComplete(Flow flow, java.lang.Throwable flowEscalation, EscalationCompletion completion)
Flags that the inputFlow
has completed.GovernanceContainer<?>
getGovernanceContainer(int index)
Obtains theGovernanceContainer
for the input index.ManagedObjectContainer
getManagedObjectContainer(int index)
Obtains theManagedObjectContainer
for the input index.int
getMaximumFunctionChainLength()
Obtains the maximumFunctionState
chain length for thisThreadState
.ProcessState
getProcessState()
Obtains theProcessState
of the process containing thisThreadState
.FunctionState
handleEscalation(java.lang.Throwable escalation, EscalationCompletion completion)
boolean
isAttachedToThread()
Indicates if thisThreadState
is attached to the currentThread
.boolean
isGovernanceActive(int index)
Indicates if theGovernance
is active.boolean
isThreadStateSafe()
Indicates if changes to theThreadState
are safe on the currentThread
.void
profile(ManagedFunctionLogicMetaData functionMetaData)
Profiles thatManagedObjectContainer
is being executed.FunctionState
registerThreadProfiler()
Obtains theFunctionState
to register theThreadProfiler
.<R,T extends java.lang.Throwable>
RrunProcessSafeOperation(ProcessSafeOperation<R,T> operation)
Runs theProcessSafeOperation
.<R,T extends java.lang.Throwable>
RrunThreadSafeOperation(ThreadSafeOperation<R,T> operation)
Run theThreadSafeOperation
.FunctionState
runWithin(FunctionState function)
Runs theFunctionState
within thisThreadState
.FunctionState
then(FunctionState function, FunctionState thenFunction)
CreatesFunctionState
to execute the chain of the firstFunctionState
before moving onto execute the chain of the secondFunctionState
.-
Methods inherited from interface net.officefloor.frame.internal.structure.LinkedListSetEntry
getLinkedListSetOwner, getNext, getPrev, setNext, setPrev
-
-
-
-
Method Detail
-
isAttachedToThread
boolean isAttachedToThread()
Indicates if thisThreadState
is attached to the currentThread
.- Returns:
true
ifThreadState
is attached to the currentThread
.
-
isThreadStateSafe
boolean isThreadStateSafe()
Indicates if changes to theThreadState
are safe on the currentThread
.- Returns:
true
should changes to theThreadState
be safe on the currentThread
.
-
then
FunctionState then(FunctionState function, FunctionState thenFunction)
CreatesFunctionState
to execute the chain of the firstFunctionState
before moving onto execute the chain of the secondFunctionState
.- Parameters:
function
- Head of initialFunctionState
chain to complete.thenFunction
- Head of the secondFunctionState
chain to then complete next.- Returns:
FunctionState
to execute the chains one after another.
-
runWithin
FunctionState runWithin(FunctionState function)
Runs theFunctionState
within thisThreadState
.- Parameters:
function
-FunctionState
to run within thisThreadState
.- Returns:
FunctionState
running within thisThreadState
.
-
avoidTeam
AvoidTeam avoidTeam(FunctionState function, TeamManagement team)
Runs avoiding the specifiedTeam
.- Parameters:
function
-FunctionState
to avoid being executed by the specifiedTeam
.team
-TeamManagement
ofTeam
to avoid.- Returns:
AvoidTeam
.
-
getMaximumFunctionChainLength
int getMaximumFunctionChainLength()
Obtains the maximum
FunctionState
chain length for thisThreadState
.Once the
FunctionState
chain has reached this length, it will be broken. (spawned in anotherThread
). This avoidsStackOverflowError
issues inFunctionState
chain being too large.- Returns:
- Maximum
FunctionState
chain length for thisThreadState
.
-
runThreadSafeOperation
<R,T extends java.lang.Throwable> R runThreadSafeOperation(ThreadSafeOperation<R,T> operation) throws T extends java.lang.Throwable
Run the
ThreadSafeOperation
.Initially locks are not taken to make the main
ThreadState
safe. This ensures theThreadSafeOperation
is run under critical section of thisThreadState
.- Type Parameters:
R
- Return type fromThreadSafeOperation
.T
- PossibleEscalation
fromThreadSafeOperation
.- Parameters:
operation
-ThreadSafeOperation
.- Returns:
- Optional return value from
ThreadSafeOperation
. - Throws:
T
- OptionalThrowable
fromThreadSafeOperation
.T extends java.lang.Throwable
-
runProcessSafeOperation
<R,T extends java.lang.Throwable> R runProcessSafeOperation(ProcessSafeOperation<R,T> operation) throws T extends java.lang.Throwable
Runs theProcessSafeOperation
.- Type Parameters:
R
- Return type fromProcessSafeOperation
.T
- PossibleEscalation
fromProcessSafeOperation
.- Parameters:
operation
-ProcessSafeOperation
.- Returns:
- Optional return value from
ProcessSafeOperation
. - Throws:
T
- OptionalThrowable
fromProcessSafeOperation
.T extends java.lang.Throwable
-
createFlow
Flow createFlow(FlowCompletion flowCompletion, EscalationCompletion escalationCompletion)
Creates aFlow
contained in thisThreadState
.- Parameters:
flowCompletion
- OptionalFlowCompletion
to handle completion of theFlow
. May benull
.escalationCompletion
- OptionalEscalationCompletion
to handle completion ofFlow
and notifyEscalation
handling complete. May benull
.- Returns:
- New
Flow
.
-
handleEscalation
FunctionState handleEscalation(java.lang.Throwable escalation, EscalationCompletion completion)
- Parameters:
escalation
-Escalation
.completion
- OptionalEscalationCompletion
to be notified of completion ofEscalation
handling.- Returns:
FunctionState
to handle theEscalation
.
-
flowComplete
FunctionState flowComplete(Flow flow, java.lang.Throwable flowEscalation, EscalationCompletion completion)
Flags that the inputFlow
has completed.- Parameters:
flow
-Flow
that has completed.flowEscalation
- PossibleEscalation
from theFlow
. May benull
.completion
-EscalationCompletion
. May benull
.- Returns:
- Optional
FunctionState
to complete theFlow
.
-
getProcessState
ProcessState getProcessState()
Obtains theProcessState
of the process containing thisThreadState
.- Returns:
ProcessState
of the process containing thisThreadState
.
-
getManagedObjectContainer
ManagedObjectContainer getManagedObjectContainer(int index)
Obtains theManagedObjectContainer
for the input index.- Parameters:
index
- Index of theManagedObjectContainer
to be returned.- Returns:
ManagedObjectContainer
for the index.
-
getGovernanceContainer
GovernanceContainer<?> getGovernanceContainer(int index)
Obtains theGovernanceContainer
for the input index.- Parameters:
index
- Index of theGovernanceContainer
to be returned.- Returns:
GovernanceContainer
for the index only if active. If not active will returnnull
.
-
isGovernanceActive
boolean isGovernanceActive(int index)
Indicates if the
Governance
is active.This provides a quick check and avoids creation of the
GovernanceContainer
.- Parameters:
index
- Index of theGovernance
to check active.- Returns:
true
if theGovernance
is active.
-
registerThreadProfiler
FunctionState registerThreadProfiler()
Obtains theFunctionState
to register theThreadProfiler
.- Returns:
FunctionState
to register theThreadProfiler
. May benull
if noThreadProfiler
required.
-
profile
void profile(ManagedFunctionLogicMetaData functionMetaData)
Profiles thatManagedObjectContainer
is being executed.- Parameters:
functionMetaData
-ManagedFunctionLogicMetaData
of theManagedFunctionContainer
being executed.
-
-