Package rife.workflow

Class Workflow

java.lang.Object
rife.workflow.Workflow

public class Workflow extends Object
Runs work and dispatches events to work that is paused.

Note that this workflow executes the work, but doesn't create a new thread for itself. When a workflow is used, you should take the necessary steps to keep the application running for as long as you need the work to be available.

Since:
1.0
API Note:
The workflow engine is still in an ALPHA EXPERIMENTAL STAGE and might change.
  • Constructor Details

    • Workflow

      public Workflow()
      Creates a new workflow instance with a cached thread pool.
      Since:
      1.0
    • Workflow

      public Workflow(ExecutorService executor)
      Creates a new workflow instance with a provided executor.
      Parameters:
      executor - the executor to use for running the work
      Since:
      1.0
    • Workflow

      public Workflow(HierarchicalProperties properties)
      Creates a new workflow instance with a provided parent properties.
      Parameters:
      properties - the parent hierarchical properties
      Since:
      1.0
    • Workflow

      public Workflow(ExecutorService executor, HierarchicalProperties properties)
      Creates a new workflow instance.
      Parameters:
      executor - the executor to use for running the work
      properties - the parent hierarchical properties
      Since:
      1.0
  • Method Details

    • properties

      public HierarchicalProperties properties()
      Retrieves the hierarchical properties for this workflow instance.
      Returns:
      this workflow's collection of hierarchical properties
      Since:
      1.0
    • start

      public Workflow start(Class<? extends Work> klass)
      Starts the execution of a new work instance.
      Parameters:
      klass - the work class whose instance that should be executed, the class should extend Work
      Since:
      1.0
    • start

      public Workflow start(Work work)
      Starts the execution of a new work instance.
      Parameters:
      work - the work that should be executed
      Returns:
      this workflow instance
      Since:
      1.0
    • inform

      public void inform(Object type)
      Convenience method that informs about an event in a workflow.
      Parameters:
      type - the type of the event
      Since:
      1.0
      See Also:
    • inform

      public void inform(Object type, Object data)
      Convenience method that informs about an event in a workflow with associated data.
      Parameters:
      type - the type of the event
      data - the data that will be sent with the event
      Since:
      1.0
      See Also:
    • inform

      public void inform(Event event)
      Informs about an event that wakes up work if it is paused for the event type.

      If events are informed about and no work is ready to consume them, they will be lost. This is different from events being triggered.

      Parameters:
      event - the event
      Since:
      1.0
      See Also:
    • trigger

      public void trigger(Object type)
      Convenience method that triggers an event in a workflow.
      Parameters:
      type - the type of the event
      Since:
      1.0
      See Also:
    • trigger

      public void trigger(Object type, Object data)
      Convenience method that triggers an event in a workflow with associated data.
      Parameters:
      type - the type of the event
      data - the data that will be sent with the event
      Since:
      1.0
      See Also:
    • trigger

      public void trigger(Event event)
      Triggers an event that wakes up work that is paused for the event type.

      If events are triggered, and no work is ready to consume them, they will be queued up until the first available work arrives.

      Parameters:
      event - the event
      Since:
      1.0
      See Also:
    • waitForPausedWork

      public void waitForPausedWork() throws InterruptedException
      Causes the calling thread to wait until work is paused for events.
      Throws:
      InterruptedException - when the current thread is interrupted
      Since:
      1.0
    • waitForNoWork

      public void waitForNoWork() throws InterruptedException
      Causes the calling thread to wait until no more work is running.
      Throws:
      InterruptedException - when the current thread is interrupted
      Since:
      1.0
    • addListener

      public void addListener(EventListener listener)
      Adds a new event listener.
      Parameters:
      listener - the event listener that will be added
      Since:
      1.0
      See Also:
    • removeListener

      public void removeListener(EventListener listener)
      Removes an event listener.
      Parameters:
      listener - the event listener that will be removed
      Since:
      1.0
      See Also: