Package io.temporal.workflow
Class WorkflowLocal<T>
- java.lang.Object
-
- io.temporal.workflow.WorkflowLocal<T>
-
public final class WorkflowLocal<T> extends java.lang.ObjectA value that is local to a single workflow execution. So it can act as a global variable for the workflow code. For example theWorkflow.isSignaled()static method returns the correct value even if there are multiple workflows executing on the same machine simultaneously. It would be invalid if thesignaledwas astatic booleanvariable.public class Workflow { private static final WorkflowLocal<Boolean> signaled = WorkflowLocal.withCachedInitial(() -> false); public static boolean isSignaled() { return signaled.get(); } public void signal() { signaled.set(true); } }
-
-
Constructor Summary
Constructors Constructor Description WorkflowLocal()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Tget()voidset(T value)static <S> WorkflowLocal<S>withCachedInitial(java.util.function.Supplier<? extends S> supplier)Create an instance that returns the value returned by the givenSupplierwhen#set(S)has not yet been called in the Workflow, and then stores the returned value inside theWorkflowLocal.static <S> WorkflowLocal<S>withInitial(java.util.function.Supplier<? extends S> supplier)Deprecated.Because the non-caching behavior of this API is typically not desirable, it's recommend to usewithCachedInitial(Supplier)instead.
-
-
-
Method Detail
-
withInitial
@Deprecated public static <S> WorkflowLocal<S> withInitial(java.util.function.Supplier<? extends S> supplier)
Deprecated.Because the non-caching behavior of this API is typically not desirable, it's recommend to usewithCachedInitial(Supplier)instead.Create an instance that returns the value returned by the givenSupplierwhen#set(S)has not yet been called in the Workflow. Note that the value returned by theSupplieris not stored in theWorkflowLocalimplicitly; repeatedly callingget()will always re-execute theSupplieruntil you call#set(S)for the first time. If you want the value returned by theSupplierto be stored in theWorkflowLocal, usewithCachedInitial(Supplier)instead.- Type Parameters:
S- The type stored in theWorkflowLocal.- Parameters:
supplier- Callback that will be executed wheneverget()is called, until#set(S)is called for the first time.- Returns:
- A
WorkflowLocalinstance.
-
withCachedInitial
public static <S> WorkflowLocal<S> withCachedInitial(java.util.function.Supplier<? extends S> supplier)
Create an instance that returns the value returned by the givenSupplierwhen#set(S)has not yet been called in the Workflow, and then stores the returned value inside theWorkflowLocal.- Type Parameters:
S- The type stored in theWorkflowLocal.- Parameters:
supplier- Callback that will be executed whenget()is called for the first time, if#set(S)has not already been called.- Returns:
- A
WorkflowLocalinstance.
-
get
public T get()
-
set
public void set(T value)
-
-