Class WorkflowLocal<T>

java.lang.Object
io.temporal.workflow.WorkflowLocal<T>

public final class WorkflowLocal<T> extends Object
A value that is local to a single workflow execution. So it can act as a global variable for the workflow code. For example the Workflow.isSignaled() static method returns the correct value even if there are multiple workflows executing on the same machine simultaneously. It would be invalid if the signaled was a static boolean variable.

 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);
   }
 }
 
See Also:
  • Constructor Details

    • WorkflowLocal

      public WorkflowLocal()
  • Method Details

    • withInitial

      @Deprecated public static <S> WorkflowLocal<S> withInitial(Supplier<? extends S> supplier)
      Deprecated.
      Because the non-caching behavior of this API is typically not desirable, it's recommend to use withCachedInitial(Supplier) instead.
      Create an instance that returns the value returned by the given Supplier when set(Object) has not yet been called in the Workflow. Note that the value returned by the Supplier is not stored in the WorkflowLocal implicitly; repeatedly calling get() will always re-execute the Supplier until you call set(Object) for the first time. If you want the value returned by the Supplier to be stored in the WorkflowLocal, use withCachedInitial(Supplier) instead.
      Type Parameters:
      S - The type stored in the WorkflowLocal.
      Parameters:
      supplier - Callback that will be executed whenever get() is called, until set(Object) is called for the first time.
      Returns:
      A WorkflowLocal instance.
    • withCachedInitial

      public static <S> WorkflowLocal<S> withCachedInitial(Supplier<? extends S> supplier)
      Create an instance that returns the value returned by the given Supplier when set(Object) has not yet been called in the Workflow, and then stores the returned value inside the WorkflowLocal.
      Type Parameters:
      S - The type stored in the WorkflowLocal.
      Parameters:
      supplier - Callback that will be executed when get() is called for the first time, if set(Object) has not already been called.
      Returns:
      A WorkflowLocal instance.
    • get

      public T get()
    • set

      public void set(T value)