Class ThreadStateImpl
- All Implemented Interfaces:
LinkedListSetEntry<ThreadState,,ProcessState> ThreadState
ThreadState.- Author:
- Daniel Sagenschneider
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinkedListSet<Flow,ThreadState> ActiveFlowinstances for thisThreadState. -
Constructor Summary
ConstructorsConstructorDescriptionThreadStateImpl(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
Modifier and TypeMethodDescriptionstatic ThreadStateContextattachThreadStateToThread(ThreadState threadState, boolean isRequireThreadStateSafe) Attaches theThreadStateto theThread.avoidTeam(FunctionState function, TeamManagement team) Runs avoiding the specifiedTeam.createFlow(FlowCompletion flowCompletion, EscalationCompletion escalationCompletion) Creates aFlowcontained in thisThreadState.static ProcessIdentifierObtains the currentProcessStateProcessIdentifier.static ThreadStateContextcurrentThreadContext(ThreadState fallbackThreadState) Obtains the currentThreadStateContext.static voidDetaches theThreadStatefrom theThread.flowComplete(Flow flow, Throwable threadEscalation, EscalationCompletion escalationCompletion) Flags that the inputFlowhas completed.getGovernanceContainer(int index) Obtains theGovernanceContainerfor the input index.Obtains the owner of theLinkedListSetthat thisLinkedListSetEntrymay be added.getManagedObjectContainer(int index) Obtains theManagedObjectContainerfor the input index.intObtains the maximumFunctionStatechain length for thisThreadState.Obtains theProcessStateof the process containing thisThreadState.handleEscalation(Throwable escalation, EscalationCompletion escalationCompletion) 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 class net.officefloor.frame.impl.execute.linkedlistset.AbstractLinkedListSetEntry
getNext, getPrev, setNext, setPrevMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.officefloor.frame.internal.structure.LinkedListSetEntry
getNext, getPrev, setNext, setPrev
-
Field Details
-
activeFlows
ActiveFlowinstances for thisThreadState.
-
-
Constructor Details
-
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 Details
-
attachThreadStateToThread
public static ThreadStateContext attachThreadStateToThread(ThreadState threadState, boolean isRequireThreadStateSafe) Attaches theThreadStateto theThread.- Parameters:
threadState-ThreadStateto attached to theThread.isRequireThreadStateSafe-trueto provideThreadsafety on executing theFunctionStateinstances.- Returns:
ThreadStateContextfor executing theThreadStateattached to theThread.
-
detachThreadStateFromThread
public static void detachThreadStateFromThread()Detaches theThreadStatefrom theThread. -
currentProcessIdentifier
Obtains the currentProcessStateProcessIdentifier.- Returns:
- Current
ProcessStateProcessIdentifierornullif outside management.
-
currentThreadContext
Obtains the currentThreadStateContext.- Parameters:
fallbackThreadState- Fall backThreadStateif noThreadStatebound toThread.- Returns:
- Current
ThreadStateContext.
-
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.
-
lockThreadState
public void lockThreadState()Description copied from interface:ThreadStateLocks thisThreadStateto currentThread.- Specified by:
lockThreadStatein interfaceThreadState
-
then
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
Description copied from interface:ThreadStateRuns theFunctionStatewithin thisThreadState.- Specified by:
runWithinin interfaceThreadState- Parameters:
function-FunctionStateto run within thisThreadState.- Returns:
FunctionStaterunning within thisThreadState.
-
avoidTeam
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 Throwable> R runThreadSafeOperation(ThreadSafeOperation<R, T> operation) throws TDescription 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.
-
runProcessSafeOperation
public <R,T extends Throwable> R runProcessSafeOperation(ProcessSafeOperation<R, T> operation) throws TDescription 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.
-
createFlow
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(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, 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
Description copied from interface:ThreadStateObtains theProcessStateof the process containing thisThreadState.- Specified by:
getProcessStatein interfaceThreadState- Returns:
ProcessStateof the process containing thisThreadState.
-
getManagedObjectContainer
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
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
Description copied from interface:ThreadStateObtains theFunctionStateto register theThreadProfiler.- Specified by:
registerThreadProfilerin interfaceThreadState- Returns:
FunctionStateto register theThreadProfiler. May benullif noThreadProfilerrequired.
-
profile
Description copied from interface:ThreadStateProfiles thatManagedObjectContaineris being executed.- Specified by:
profilein interfaceThreadState- Parameters:
functionMetaData-ManagedFunctionLogicMetaDataof theManagedFunctionContainerbeing executed.
-