Class ThreadStateImpl
- java.lang.Object
-
- net.officefloor.frame.impl.execute.linkedlistset.AbstractLinkedListSetEntry<ThreadState,ProcessState>
-
- net.officefloor.frame.impl.execute.thread.ThreadStateImpl
-
- All Implemented Interfaces:
LinkedListSetEntry<ThreadState,ProcessState>
,ThreadState
public class ThreadStateImpl extends AbstractLinkedListSetEntry<ThreadState,ProcessState> implements ThreadState
Implementation of theThreadState
.- Author:
- Daniel Sagenschneider
-
-
Field Summary
Fields Modifier and Type Field Description protected LinkedListSet<Flow,ThreadState>
activeFlows
ActiveFlow
instances for thisThreadState
.
-
Constructor Summary
Constructors Constructor Description ThreadStateImpl(ThreadMetaData threadMetaData, FlowCallback callback, ThreadState callbackThreadState, ProcessState processState, ProcessProfiler processProfiler)
Initiate withProcessState
FlowCallback
.ThreadStateImpl(ThreadMetaData threadMetaData, FlowCompletion completion, boolean isEscalationHandlingThreadState, ProcessState processState, ProcessProfiler processProfiler)
Initiate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ThreadStateContext
attachThreadStateToThread(ThreadState threadState, boolean isThreadStateSafe)
Attaches theThreadState
to theThread
.AvoidTeam
avoidTeam(FunctionState function, TeamManagement team)
Runs avoiding the specifiedTeam
.Flow
createFlow(FlowCompletion flowCompletion, EscalationCompletion escalationCompletion)
Creates aFlow
contained in thisThreadState
.static ProcessIdentifier
currentProcessIdentifier()
Obtains the currentProcessState
ProcessIdentifier
.static ThreadStateContext
currentThreadContext(ThreadState fallbackThreadState)
Obtains the currentThreadStateContext
.static void
detachThreadStateFromThread()
Detaches theThreadState
from theThread
.FunctionState
flowComplete(Flow flow, java.lang.Throwable threadEscalation, EscalationCompletion escalationCompletion)
Flags that the inputFlow
has completed.GovernanceContainer<?>
getGovernanceContainer(int index)
Obtains theGovernanceContainer
for the input index.ProcessState
getLinkedListSetOwner()
Obtains the owner of theLinkedListSet
that thisLinkedListSetEntry
may be added.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 escalationCompletion)
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 class net.officefloor.frame.impl.execute.linkedlistset.AbstractLinkedListSetEntry
getNext, getPrev, setNext, setPrev
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.officefloor.frame.internal.structure.LinkedListSetEntry
getNext, getPrev, setNext, setPrev
-
-
-
-
Field Detail
-
activeFlows
protected final LinkedListSet<Flow,ThreadState> activeFlows
ActiveFlow
instances for thisThreadState
.
-
-
Constructor Detail
-
ThreadStateImpl
public ThreadStateImpl(ThreadMetaData threadMetaData, FlowCallback callback, ThreadState callbackThreadState, ProcessState processState, ProcessProfiler processProfiler)
Initiate withProcessState
FlowCallback
.- Parameters:
threadMetaData
-ThreadMetaData
for thisThreadState
.callback
-ProcessState
FlowCallback
.callbackThreadState
-FlowCallback
ThreadState
.processState
-ProcessState
for thisThreadState
.processProfiler
-ProcessProfiler
. May benull
.
-
ThreadStateImpl
public ThreadStateImpl(ThreadMetaData threadMetaData, FlowCompletion completion, boolean isEscalationHandlingThreadState, ProcessState processState, ProcessProfiler processProfiler)
Initiate.- Parameters:
threadMetaData
-ThreadMetaData
for thisThreadState
.completion
-FlowCompletion
for thisThreadState
.isEscalationHandlingThreadState
-true
if thisThreadState
was spawned to handle anEscalation
.false
to indicate aThreadState
for normal execution.processState
-ProcessState
for thisThreadState
.processProfiler
-ProcessProfiler
. May benull
.
-
-
Method Detail
-
attachThreadStateToThread
public static ThreadStateContext attachThreadStateToThread(ThreadState threadState, boolean isThreadStateSafe)
Attaches theThreadState
to theThread
.- Parameters:
threadState
-ThreadState
to attached to theThread
.isThreadStateSafe
- Indicates if the execution isThreadState
safe.- Returns:
ThreadStateContext
for executing theThreadState
attached to theThread
.
-
detachThreadStateFromThread
public static void detachThreadStateFromThread()
Detaches theThreadState
from theThread
.
-
currentProcessIdentifier
public static ProcessIdentifier currentProcessIdentifier()
Obtains the currentProcessState
ProcessIdentifier
.- Returns:
- Current
ProcessState
ProcessIdentifier
ornull
if outside management.
-
currentThreadContext
public static ThreadStateContext currentThreadContext(ThreadState fallbackThreadState)
Obtains the currentThreadStateContext
.- Parameters:
fallbackThreadState
- Fall backThreadState
if noThreadState
bound toThread
.- Returns:
- Current
ThreadStateContext
.
-
getLinkedListSetOwner
public ProcessState getLinkedListSetOwner()
Description copied from interface:LinkedListSetEntry
Obtains the owner of the
LinkedListSet
that thisLinkedListSetEntry
may be added.LinkedListSetEntry
instances may only be added to theLinkedListSet
they were intended for and can not be shared betweenLinkedListSet
instances. This constraint:- ensures the integrity of the
FunctionState
,Flow
,ThreadState
,ProcessState
structure, and - improves uniqueness performance as
LinkedListSetEntry.getNext()
andLinkedListSetEntry.getPrev()
both returningnull
indicates not added
- Specified by:
getLinkedListSetOwner
in interfaceLinkedListSetEntry<ThreadState,ProcessState>
- Returns:
- Owner of the
LinkedListSet
that may contain thisLinkedListSetEntry
.
- ensures the integrity of the
-
isAttachedToThread
public boolean isAttachedToThread()
Description copied from interface:ThreadState
Indicates if thisThreadState
is attached to the currentThread
.- Specified by:
isAttachedToThread
in interfaceThreadState
- Returns:
true
ifThreadState
is attached to the currentThread
.
-
isThreadStateSafe
public boolean isThreadStateSafe()
Description copied from interface:ThreadState
Indicates if changes to theThreadState
are safe on the currentThread
.- Specified by:
isThreadStateSafe
in interfaceThreadState
- Returns:
true
should changes to theThreadState
be safe on the currentThread
.
-
then
public FunctionState then(FunctionState function, FunctionState thenFunction)
Description copied from interface:ThreadState
CreatesFunctionState
to execute the chain of the firstFunctionState
before moving onto execute the chain of the secondFunctionState
.- Specified by:
then
in interfaceThreadState
- 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
public FunctionState runWithin(FunctionState function)
Description copied from interface:ThreadState
Runs theFunctionState
within thisThreadState
.- Specified by:
runWithin
in interfaceThreadState
- Parameters:
function
-FunctionState
to run within thisThreadState
.- Returns:
FunctionState
running within thisThreadState
.
-
avoidTeam
public AvoidTeam avoidTeam(FunctionState function, TeamManagement team)
Description copied from interface:ThreadState
Runs avoiding the specifiedTeam
.- Specified by:
avoidTeam
in interfaceThreadState
- Parameters:
function
-FunctionState
to avoid being executed by the specifiedTeam
.team
-TeamManagement
ofTeam
to avoid.- Returns:
AvoidTeam
.
-
getMaximumFunctionChainLength
public int getMaximumFunctionChainLength()
Description copied from interface:ThreadState
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.- Specified by:
getMaximumFunctionChainLength
in interfaceThreadState
- Returns:
- Maximum
FunctionState
chain length for thisThreadState
.
-
runThreadSafeOperation
public <R,T extends java.lang.Throwable> R runThreadSafeOperation(ThreadSafeOperation<R,T> operation) throws T extends java.lang.Throwable
Description copied from interface:ThreadState
Run the
ThreadSafeOperation
.Initially locks are not taken to make the main
ThreadState
safe. This ensures theThreadSafeOperation
is run under critical section of thisThreadState
.- Specified by:
runThreadSafeOperation
in interfaceThreadState
- 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
public <R,T extends java.lang.Throwable> R runProcessSafeOperation(ProcessSafeOperation<R,T> operation) throws T extends java.lang.Throwable
Description copied from interface:ThreadState
Runs theProcessSafeOperation
.- Specified by:
runProcessSafeOperation
in interfaceThreadState
- 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
public Flow createFlow(FlowCompletion flowCompletion, EscalationCompletion escalationCompletion)
Description copied from interface:ThreadState
Creates aFlow
contained in thisThreadState
.- Specified by:
createFlow
in interfaceThreadState
- 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
public FunctionState handleEscalation(java.lang.Throwable escalation, EscalationCompletion escalationCompletion)
Description copied from interface:ThreadState
- Specified by:
handleEscalation
in interfaceThreadState
- Parameters:
escalation
-Escalation
.escalationCompletion
- OptionalEscalationCompletion
to be notified of completion ofEscalation
handling.- Returns:
FunctionState
to handle theEscalation
.
-
flowComplete
public FunctionState flowComplete(Flow flow, java.lang.Throwable threadEscalation, EscalationCompletion escalationCompletion)
Description copied from interface:ThreadState
Flags that the inputFlow
has completed.- Specified by:
flowComplete
in interfaceThreadState
- Parameters:
flow
-Flow
that has completed.threadEscalation
- PossibleEscalation
from theFlow
. May benull
.escalationCompletion
-EscalationCompletion
. May benull
.- Returns:
- Optional
FunctionState
to complete theFlow
.
-
getProcessState
public ProcessState getProcessState()
Description copied from interface:ThreadState
Obtains theProcessState
of the process containing thisThreadState
.- Specified by:
getProcessState
in interfaceThreadState
- Returns:
ProcessState
of the process containing thisThreadState
.
-
getManagedObjectContainer
public ManagedObjectContainer getManagedObjectContainer(int index)
Description copied from interface:ThreadState
Obtains theManagedObjectContainer
for the input index.- Specified by:
getManagedObjectContainer
in interfaceThreadState
- Parameters:
index
- Index of theManagedObjectContainer
to be returned.- Returns:
ManagedObjectContainer
for the index.
-
getGovernanceContainer
public GovernanceContainer<?> getGovernanceContainer(int index)
Description copied from interface:ThreadState
Obtains theGovernanceContainer
for the input index.- Specified by:
getGovernanceContainer
in interfaceThreadState
- Parameters:
index
- Index of theGovernanceContainer
to be returned.- Returns:
GovernanceContainer
for the index only if active. If not active will returnnull
.
-
isGovernanceActive
public boolean isGovernanceActive(int index)
Description copied from interface:ThreadState
Indicates if the
Governance
is active.This provides a quick check and avoids creation of the
GovernanceContainer
.- Specified by:
isGovernanceActive
in interfaceThreadState
- Parameters:
index
- Index of theGovernance
to check active.- Returns:
true
if theGovernance
is active.
-
registerThreadProfiler
public FunctionState registerThreadProfiler()
Description copied from interface:ThreadState
Obtains theFunctionState
to register theThreadProfiler
.- Specified by:
registerThreadProfiler
in interfaceThreadState
- Returns:
FunctionState
to register theThreadProfiler
. May benull
if noThreadProfiler
required.
-
profile
public void profile(ManagedFunctionLogicMetaData functionMetaData)
Description copied from interface:ThreadState
Profiles thatManagedObjectContainer
is being executed.- Specified by:
profile
in interfaceThreadState
- Parameters:
functionMetaData
-ManagedFunctionLogicMetaData
of theManagedFunctionContainer
being executed.
-
-