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>activeFlowsActiveFlowinstances for thisThreadState.
-
Constructor Summary
Constructors Constructor Description ThreadStateImpl(ThreadMetaData threadMetaData, FlowCallback callback, ThreadState callbackThreadState, ProcessState processState, ProcessProfiler processProfiler)Initiate withProcessStateFlowCallback.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 ThreadStateContextattachThreadStateToThread(ThreadState threadState, boolean isThreadStateSafe)Attaches theThreadStateto theThread.AvoidTeamavoidTeam(FunctionState function, TeamManagement team)Runs avoiding the specifiedTeam.FlowcreateFlow(FlowCompletion flowCompletion, EscalationCompletion escalationCompletion)Creates aFlowcontained in thisThreadState.static ProcessIdentifiercurrentProcessIdentifier()Obtains the currentProcessStateProcessIdentifier.static ThreadStateContextcurrentThreadContext(ThreadState fallbackThreadState)Obtains the currentThreadStateContext.static voiddetachThreadStateFromThread()Detaches theThreadStatefrom theThread.FunctionStateflowComplete(Flow flow, java.lang.Throwable threadEscalation, EscalationCompletion escalationCompletion)Flags that the inputFlowhas completed.GovernanceContainer<?>getGovernanceContainer(int index)Obtains theGovernanceContainerfor the input index.ProcessStategetLinkedListSetOwner()Obtains the owner of theLinkedListSetthat thisLinkedListSetEntrymay be added.ManagedObjectContainergetManagedObjectContainer(int index)Obtains theManagedObjectContainerfor the input index.intgetMaximumFunctionChainLength()Obtains the maximumFunctionStatechain length for thisThreadState.ProcessStategetProcessState()Obtains theProcessStateof the process containing thisThreadState.FunctionStatehandleEscalation(java.lang.Throwable escalation, EscalationCompletion escalationCompletion)booleanisAttachedToThread()Indicates if thisThreadStateis attached to the currentThread.booleanisGovernanceActive(int index)Indicates if theGovernanceis active.booleanisThreadStateSafe()Indicates if changes to theThreadStateare safe on the currentThread.voidprofile(ManagedFunctionLogicMetaData functionMetaData)Profiles thatManagedObjectContaineris being executed.FunctionStateregisterThreadProfiler()Obtains theFunctionStateto 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.FunctionStaterunWithin(FunctionState function)Runs theFunctionStatewithin thisThreadState.FunctionStatethen(FunctionState function, FunctionState thenFunction)CreatesFunctionStateto execute the chain of the firstFunctionStatebefore 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
ActiveFlowinstances for thisThreadState.
-
-
Constructor Detail
-
ThreadStateImpl
public ThreadStateImpl(ThreadMetaData threadMetaData, FlowCallback callback, ThreadState callbackThreadState, ProcessState processState, ProcessProfiler processProfiler)
Initiate withProcessStateFlowCallback.- Parameters:
threadMetaData-ThreadMetaDatafor thisThreadState.callback-ProcessStateFlowCallback.callbackThreadState-FlowCallbackThreadState.processState-ProcessStatefor thisThreadState.processProfiler-ProcessProfiler. May benull.
-
ThreadStateImpl
public ThreadStateImpl(ThreadMetaData threadMetaData, FlowCompletion completion, boolean isEscalationHandlingThreadState, ProcessState processState, ProcessProfiler processProfiler)
Initiate.- Parameters:
threadMetaData-ThreadMetaDatafor thisThreadState.completion-FlowCompletionfor thisThreadState.isEscalationHandlingThreadState-trueif thisThreadStatewas spawned to handle anEscalation.falseto indicate aThreadStatefor normal execution.processState-ProcessStatefor thisThreadState.processProfiler-ProcessProfiler. May benull.
-
-
Method Detail
-
attachThreadStateToThread
public static ThreadStateContext attachThreadStateToThread(ThreadState threadState, boolean isThreadStateSafe)
Attaches theThreadStateto theThread.- Parameters:
threadState-ThreadStateto attached to theThread.isThreadStateSafe- Indicates if the execution isThreadStatesafe.- Returns:
ThreadStateContextfor executing theThreadStateattached to theThread.
-
detachThreadStateFromThread
public static void detachThreadStateFromThread()
Detaches theThreadStatefrom theThread.
-
currentProcessIdentifier
public static ProcessIdentifier currentProcessIdentifier()
Obtains the currentProcessStateProcessIdentifier.- Returns:
- Current
ProcessStateProcessIdentifierornullif outside management.
-
currentThreadContext
public static ThreadStateContext currentThreadContext(ThreadState fallbackThreadState)
Obtains the currentThreadStateContext.- Parameters:
fallbackThreadState- Fall backThreadStateif noThreadStatebound toThread.- Returns:
- Current
ThreadStateContext.
-
getLinkedListSetOwner
public ProcessState getLinkedListSetOwner()
Description copied from interface:LinkedListSetEntryObtains the owner of the
LinkedListSetthat thisLinkedListSetEntrymay be added.LinkedListSetEntryinstances may only be added to theLinkedListSetthey were intended for and can not be shared betweenLinkedListSetinstances. This constraint:- ensures the integrity of the
FunctionState,Flow,ThreadState,ProcessStatestructure, and - improves uniqueness performance as
LinkedListSetEntry.getNext()andLinkedListSetEntry.getPrev()both returningnullindicates not added
- Specified by:
getLinkedListSetOwnerin interfaceLinkedListSetEntry<ThreadState,ProcessState>- Returns:
- Owner of the
LinkedListSetthat may contain thisLinkedListSetEntry.
- ensures the integrity of the
-
isAttachedToThread
public boolean isAttachedToThread()
Description copied from interface:ThreadStateIndicates if thisThreadStateis attached to the currentThread.- Specified by:
isAttachedToThreadin interfaceThreadState- Returns:
trueifThreadStateis attached to the currentThread.
-
isThreadStateSafe
public boolean isThreadStateSafe()
Description copied from interface:ThreadStateIndicates if changes to theThreadStateare safe on the currentThread.- Specified by:
isThreadStateSafein interfaceThreadState- Returns:
trueshould changes to theThreadStatebe safe on the currentThread.
-
then
public FunctionState then(FunctionState function, FunctionState thenFunction)
Description copied from interface:ThreadStateCreatesFunctionStateto execute the chain of the firstFunctionStatebefore moving onto execute the chain of the secondFunctionState.- Specified by:
thenin interfaceThreadState- 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
public FunctionState runWithin(FunctionState function)
Description copied from interface:ThreadStateRuns theFunctionStatewithin thisThreadState.- Specified by:
runWithinin interfaceThreadState- Parameters:
function-FunctionStateto run within thisThreadState.- Returns:
FunctionStaterunning within thisThreadState.
-
avoidTeam
public AvoidTeam avoidTeam(FunctionState function, TeamManagement team)
Description copied from interface:ThreadStateRuns avoiding the specifiedTeam.- Specified by:
avoidTeamin interfaceThreadState- Parameters:
function-FunctionStateto avoid being executed by the specifiedTeam.team-TeamManagementofTeamto avoid.- Returns:
AvoidTeam.
-
getMaximumFunctionChainLength
public int getMaximumFunctionChainLength()
Description copied from interface:ThreadStateObtains 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.- Specified by:
getMaximumFunctionChainLengthin interfaceThreadState- Returns:
- Maximum
FunctionStatechain 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:ThreadStateRun the
ThreadSafeOperation.Initially locks are not taken to make the main
ThreadStatesafe. This ensures theThreadSafeOperationis run under critical section of thisThreadState.- Specified by:
runThreadSafeOperationin interfaceThreadState- Type Parameters:
R- Return type fromThreadSafeOperation.T- PossibleEscalationfromThreadSafeOperation.- Parameters:
operation-ThreadSafeOperation.- Returns:
- Optional return value from
ThreadSafeOperation. - Throws:
T- OptionalThrowablefromThreadSafeOperation.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:ThreadStateRuns theProcessSafeOperation.- Specified by:
runProcessSafeOperationin interfaceThreadState- Type Parameters:
R- Return type fromProcessSafeOperation.T- PossibleEscalationfromProcessSafeOperation.- Parameters:
operation-ProcessSafeOperation.- Returns:
- Optional return value from
ProcessSafeOperation. - Throws:
T- OptionalThrowablefromProcessSafeOperation.T extends java.lang.Throwable
-
createFlow
public Flow createFlow(FlowCompletion flowCompletion, EscalationCompletion escalationCompletion)
Description copied from interface:ThreadStateCreates aFlowcontained in thisThreadState.- Specified by:
createFlowin interfaceThreadState- Parameters:
flowCompletion- OptionalFlowCompletionto handle completion of theFlow. May benull.escalationCompletion- OptionalEscalationCompletionto handle completion ofFlowand notifyEscalationhandling complete. May benull.- Returns:
- New
Flow.
-
handleEscalation
public FunctionState handleEscalation(java.lang.Throwable escalation, EscalationCompletion escalationCompletion)
Description copied from interface:ThreadState- Specified by:
handleEscalationin interfaceThreadState- Parameters:
escalation-Escalation.escalationCompletion- OptionalEscalationCompletionto be notified of completion ofEscalationhandling.- Returns:
FunctionStateto handle theEscalation.
-
flowComplete
public FunctionState flowComplete(Flow flow, java.lang.Throwable threadEscalation, EscalationCompletion escalationCompletion)
Description copied from interface:ThreadStateFlags that the inputFlowhas completed.- Specified by:
flowCompletein interfaceThreadState- Parameters:
flow-Flowthat has completed.threadEscalation- PossibleEscalationfrom theFlow. May benull.escalationCompletion-EscalationCompletion. May benull.- Returns:
- Optional
FunctionStateto complete theFlow.
-
getProcessState
public ProcessState getProcessState()
Description copied from interface:ThreadStateObtains theProcessStateof the process containing thisThreadState.- Specified by:
getProcessStatein interfaceThreadState- Returns:
ProcessStateof the process containing thisThreadState.
-
getManagedObjectContainer
public ManagedObjectContainer getManagedObjectContainer(int index)
Description copied from interface:ThreadStateObtains theManagedObjectContainerfor the input index.- Specified by:
getManagedObjectContainerin interfaceThreadState- Parameters:
index- Index of theManagedObjectContainerto be returned.- Returns:
ManagedObjectContainerfor the index.
-
getGovernanceContainer
public GovernanceContainer<?> getGovernanceContainer(int index)
Description copied from interface:ThreadStateObtains theGovernanceContainerfor the input index.- Specified by:
getGovernanceContainerin interfaceThreadState- Parameters:
index- Index of theGovernanceContainerto be returned.- Returns:
GovernanceContainerfor the index only if active. If not active will returnnull.
-
isGovernanceActive
public boolean isGovernanceActive(int index)
Description copied from interface:ThreadStateIndicates if the
Governanceis active.This provides a quick check and avoids creation of the
GovernanceContainer.- Specified by:
isGovernanceActivein interfaceThreadState- Parameters:
index- Index of theGovernanceto check active.- Returns:
trueif theGovernanceis active.
-
registerThreadProfiler
public FunctionState registerThreadProfiler()
Description copied from interface:ThreadStateObtains theFunctionStateto register theThreadProfiler.- Specified by:
registerThreadProfilerin interfaceThreadState- Returns:
FunctionStateto register theThreadProfiler. May benullif noThreadProfilerrequired.
-
profile
public void profile(ManagedFunctionLogicMetaData functionMetaData)
Description copied from interface:ThreadStateProfiles thatManagedObjectContaineris being executed.- Specified by:
profilein interfaceThreadState- Parameters:
functionMetaData-ManagedFunctionLogicMetaDataof theManagedFunctionContainerbeing executed.
-
-