Class FlowContext

java.lang.Object
org.jboss.elemento.flow.FlowContext

public class FlowContext extends Object
General purpose context to be used as a common data structure when executing a list of asynchronous tasks in parallel, in sequence or when executing a task repeatedly while a condition evaluates to true.

The context provides a progress indicator to signal the progress of the task execution and a stack and a map for sharing data between asynchronous tasks.

Finally, the context provides methods to resolve the context as promise.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance with a noop progress implementation.
    Creates a new instance using the given progress indicator.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
     
    <T> T
    get(String key)
     
    <T> T
    get(String key, T defaultValue)
     
    boolean
    Checks if the data is empty.
    boolean
     
    boolean
     
    boolean
     
    static boolean
    Method to check if the error in a catch callback is due to a timeout.
     
    <T> T
    Retrieves the object at the top of the stack without removing it.
    <T> T
    pop()
    Removes the object at the top of the stack and returns that object.
    <T> T
    pop(T defaultValue)
    Removes the object at the top of the stack and returns that object or returns the default value, if the stack is empty.
    Returns the progress indicator for the execution of the tasks.
    <T> void
    push(T value)
    Pushes the value om top of the stack.
    <C extends FlowContext>
    elemental2.promise.Promise<C>
    reject(Object error)
     
    <C extends FlowContext>
    elemental2.promise.Promise<C>
    Resolves this context successfully as a promise.
    <C extends FlowContext, T>
    elemental2.promise.Promise<C>
    resolve(String key, T value)
    Stores the value under the given key in the map and resolves this context successfully as a promise.
    <C extends FlowContext, T>
    elemental2.promise.Promise<C>
    resolve(T value)
    Pushes the value on top of the stack and resolves this context successfully as a promise.
    <T> void
    set(String key, T value)
    Stores the value under the given key in the map.
     
     

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • FlowContext

      public FlowContext()
      Creates a new instance with a noop progress implementation.
    • FlowContext

      public FlowContext(Progress progress)
      Creates a new instance using the given progress indicator.
      Parameters:
      progress - the progress indicator to signal progress when executing the tasks
  • Method Details

    • isTimeout

      public static boolean isTimeout(Object error)
      Method to check if the error in a catch callback is due to a timeout.
    • resolve

      public <C extends FlowContext> elemental2.promise.Promise<C> resolve()
      Resolves this context successfully as a promise.
    • resolve

      public <C extends FlowContext, T> elemental2.promise.Promise<C> resolve(T value)
      Pushes the value on top of the stack and resolves this context successfully as a promise.
    • resolve

      public <C extends FlowContext, T> elemental2.promise.Promise<C> resolve(String key, T value)
      Stores the value under the given key in the map and resolves this context successfully as a promise.
    • reject

      public <C extends FlowContext> elemental2.promise.Promise<C> reject(Object error)
    • push

      public <T> void push(T value)
      Pushes the value om top of the stack.
    • peek

      public <T> T peek()
      Retrieves the object at the top of the stack without removing it.
      Type Parameters:
      T - The type of the object on top of the stack.
      Returns:
      The object at the top of the stack.
      Throws:
      EmptyStackException - if the stack is empty.
    • pop

      public <T> T pop()
      Removes the object at the top of the stack and returns that object.
      Returns:
      The object at the top of the stack.
      Throws:
      EmptyStackException - if this stack is empty.
    • pop

      public <T> T pop(T defaultValue)
      Removes the object at the top of the stack and returns that object or returns the default value, if the stack is empty.
      Returns:
      The object at the top of the stack or the default value if the stack is empty.
    • isStackEmpty

      public boolean isStackEmpty()
      Returns:
      true if the stack is empty, false otherwise.
    • set

      public <T> void set(String key, T value)
      Stores the value under the given key in the map.
    • get

      public <T> T get(String key)
      Returns:
      the object for the given key from the map or null if no such key was found.
    • get

      public <T> T get(String key, T defaultValue)
      Returns:
      the object for the given key from the context map or defaultValue if no such key was found.
    • keys

      public Set<String> keys()
      Returns:
      the set of keys stored in the map.
    • isEmpty

      public boolean isEmpty()
      Checks if the data is empty.
      Returns:
      true if the data is empty, false otherwise.
    • progress

      public Progress progress()
      Returns the progress indicator for the execution of the tasks.
    • status

      public FlowStatus status()
      Returns:
      the execution status of this context
    • isSuccessful

      public boolean isSuccessful()
      Returns:
      whether the execution was successful
    • isTimeout

      public boolean isTimeout()
      Returns:
      whether the execution ran into a timeout
    • failure

      public boolean failure()
      Returns:
      whether the execution failed
    • failureReason

      public String failureReason()
      Returns:
      the failure or null if the execution was successful or ran into a timeout
    • toString

      public String toString()
      Overrides:
      toString in class Object