Package io.temporal.internal.sync
Class RootWorkflowThreadImpl
- java.lang.Object
-
- io.temporal.internal.sync.RootWorkflowThreadImpl
-
- All Implemented Interfaces:
WorkflowThread,CancellationScope,java.lang.Runnable
public class RootWorkflowThreadImpl extends java.lang.Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStackTrace(java.lang.StringBuilder result)voidcancel()Cancels the scope as well as all its childrenvoidcancel(java.lang.String reason)Cancels the scope as well as all its children.voidevaluateInCoroutineContext(Functions.Proc1<java.lang.String> function)Evaluates function in the threadContext of the coroutine without unblocking it.voidexitThread()java.lang.StringgetCancellationReason()Promise<java.lang.String>getCancellationRequest()Use this promise to perform cancellation of async operations.longgetId()java.lang.StringgetName()intgetPriority()io.temporal.internal.sync.DeterministicRunnerImplgetRunner()java.lang.StringgetStackTrace()<T> java.util.Optional<java.util.Optional<T>>getThreadLocal(WorkflowThreadLocalInternal<T> key)Retrieve data from thread locals.java.lang.ThrowablegetUnhandledException()io.temporal.internal.sync.SyncWorkflowContextgetWorkflowContext()io.temporal.internal.sync.WorkflowThreadContextgetWorkflowThreadContext()booleanisCancelRequested()Is scope was asked to cancel throughCancellationScope.cancel()or by a parent scope.booleanisDetached()When set to false parent thread cancellation causes this one to get canceled automatically.booleanisDone()booleanisStarted()NonIdempotentHandlelockDeadlockDetector()Disables deadlock detector on this threadvoidrun()booleanrunUntilBlocked(long deadlockDetectionTimeoutMs)voidsetName(java.lang.String name)<T> voidsetThreadLocal(WorkflowThreadLocalInternal<T> key, T value)voidstart()java.util.concurrent.Future<?>stopNow()Interrupt coroutine by throwing DestroyWorkflowThreadError from an await method it is blocked on and return underlying Future to be waited on.voidyield(java.lang.String reason, java.util.function.Supplier<java.lang.Boolean> unblockCondition)
-
-
-
Method Detail
-
yield
public void yield(java.lang.String reason, java.util.function.Supplier<java.lang.Boolean> unblockCondition) throws DestroyWorkflowThreadError- Specified by:
yieldin interfaceWorkflowThread- Throws:
DestroyWorkflowThreadError
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
isDetached
public boolean isDetached()
Description copied from interface:CancellationScopeWhen set to false parent thread cancellation causes this one to get canceled automatically. When set to true only call toCancellationScope.cancel()leads to this scope cancellation.- Specified by:
isDetachedin interfaceCancellationScope
-
cancel
public void cancel()
Description copied from interface:CancellationScopeCancels the scope as well as all its children- Specified by:
cancelin interfaceCancellationScope
-
cancel
public void cancel(java.lang.String reason)
Description copied from interface:CancellationScopeCancels the scope as well as all its children.- Specified by:
cancelin interfaceCancellationScope- Parameters:
reason- human-readable reason for the cancellation. Becomes message of the CanceledException thrown.
-
getCancellationReason
public java.lang.String getCancellationReason()
- Specified by:
getCancellationReasonin interfaceCancellationScope
-
isCancelRequested
public boolean isCancelRequested()
Description copied from interface:CancellationScopeIs scope was asked to cancel throughCancellationScope.cancel()or by a parent scope.- Specified by:
isCancelRequestedin interfaceCancellationScope- Returns:
- whether request is canceled or not.
-
getCancellationRequest
public Promise<java.lang.String> getCancellationRequest()
Description copied from interface:CancellationScopeUse this promise to perform cancellation of async operations.- Specified by:
getCancellationRequestin interfaceCancellationScope- Returns:
- promise that becomes ready when scope is canceled. It contains reason value or null if none was provided.
-
start
public void start()
- Specified by:
startin interfaceWorkflowThread
-
isStarted
public boolean isStarted()
- Specified by:
isStartedin interfaceWorkflowThread
-
getWorkflowThreadContext
public io.temporal.internal.sync.WorkflowThreadContext getWorkflowThreadContext()
- Specified by:
getWorkflowThreadContextin interfaceWorkflowThread
-
getRunner
public io.temporal.internal.sync.DeterministicRunnerImpl getRunner()
- Specified by:
getRunnerin interfaceWorkflowThread
-
getWorkflowContext
public io.temporal.internal.sync.SyncWorkflowContext getWorkflowContext()
- Specified by:
getWorkflowContextin interfaceWorkflowThread
-
setName
public void setName(java.lang.String name)
- Specified by:
setNamein interfaceWorkflowThread
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceWorkflowThread
-
getId
public long getId()
- Specified by:
getIdin interfaceWorkflowThread
-
getPriority
public int getPriority()
- Specified by:
getPriorityin interfaceWorkflowThread
-
runUntilBlocked
public boolean runUntilBlocked(long deadlockDetectionTimeoutMs)
- Specified by:
runUntilBlockedin interfaceWorkflowThread- Parameters:
deadlockDetectionTimeoutMs- maximum time in milliseconds the thread can run before calling yield.- Returns:
- true if coroutine made some progress.
-
lockDeadlockDetector
public NonIdempotentHandle lockDeadlockDetector()
Description copied from interface:WorkflowThreadDisables deadlock detector on this thread- Specified by:
lockDeadlockDetectorin interfaceWorkflowThread- Returns:
- a handle that must be used to unlock the deadlock detector back
-
isDone
public boolean isDone()
- Specified by:
isDonein interfaceWorkflowThread
-
getUnhandledException
public java.lang.Throwable getUnhandledException()
- Specified by:
getUnhandledExceptionin interfaceWorkflowThread
-
evaluateInCoroutineContext
public void evaluateInCoroutineContext(Functions.Proc1<java.lang.String> function)
Evaluates function in the threadContext of the coroutine without unblocking it. Used to get current coroutine status, like stack trace.- Parameters:
function- Parameter is reason for current goroutine blockage.
-
stopNow
public java.util.concurrent.Future<?> stopNow()
Interrupt coroutine by throwing DestroyWorkflowThreadError from an await method it is blocked on and return underlying Future to be waited on.- Specified by:
stopNowin interfaceWorkflowThread
-
addStackTrace
public void addStackTrace(java.lang.StringBuilder result)
- Specified by:
addStackTracein interfaceWorkflowThread
-
exitThread
public void exitThread()
- Specified by:
exitThreadin interfaceWorkflowThread
-
setThreadLocal
public <T> void setThreadLocal(WorkflowThreadLocalInternal<T> key, T value)
- Specified by:
setThreadLocalin interfaceWorkflowThread
-
getThreadLocal
public <T> java.util.Optional<java.util.Optional<T>> getThreadLocal(WorkflowThreadLocalInternal<T> key)
Retrieve data from thread locals. Returns 1. not found (an empty Optional) 2. found but null (an Optional of an empty Optional) 3. found and non-null (an Optional of an Optional of a value). The type nesting is because Java Optionals cannot understand "Some null" vs "None", which is exactly what we need here.- Specified by:
getThreadLocalin interfaceWorkflowThread- Type Parameters:
T-- Parameters:
key-- Returns:
- one of three cases
-
getStackTrace
public java.lang.String getStackTrace()
- Specified by:
getStackTracein interfaceWorkflowThread- Returns:
- stack trace of the coroutine thread
-
-