Class Workflow
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.
Events are delivered to the registered listeners before any work that is paused for them is resumed. Events that work triggers after being woken up are therefore always delivered to listeners after the event that woke the work up. No ordering is guaranteed between events that are triggered concurrently from independent threads.
- Since:
- 1.0
- API Note:
- The workflow engine is in a BETA STAGE and might still change.
-
Constructor Summary
ConstructorsConstructorDescriptionWorkflow()Creates a new workflow instance with a cached thread pool.Workflow(ExecutorService executor) Creates a new workflow instance with a provided executor.Workflow(ExecutorService executor, HierarchicalProperties properties) Creates a new workflow instance.Workflow(HierarchicalProperties properties) Creates a new workflow instance with a provided parent properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddErrorListener(ErrorListener listener) Adds a new error listener that will be notified when work fails with an exception.voidaddListener(EventListener listener) Adds a new event listener.voidConvenience method that informs about an event in a workflow.voidConvenience method that informs about an event in a workflow with associated data.voidInforms about an event that wakes up work if it is paused for the event type.Retrieves the hierarchical properties for this workflow instance.voidremoveErrorListener(ErrorListener listener) Removes an error listener.voidremoveListener(EventListener listener) Removes an event listener.Starts the execution of a new work instance.Starts the execution of a new work instance.voidConvenience method that triggers an event in a workflow.voidConvenience method that triggers an event in a workflow with associated data.voidTriggers an event that wakes up work that is paused for the event type.voidCauses the calling thread to wait until no more work is running.booleanCauses the calling thread to wait until work is paused for events.
-
Constructor Details
-
Workflow
public Workflow()Creates a new workflow instance with a cached thread pool.- Since:
- 1.0
-
Workflow
Creates a new workflow instance with a provided executor.- Parameters:
executor- the executor to use for running the work- Since:
- 1.0
-
Workflow
Creates a new workflow instance with a provided parent properties.- Parameters:
properties- the parent hierarchical properties- Since:
- 1.0
-
Workflow
Creates a new workflow instance.- Parameters:
executor- the executor to use for running the workproperties- the parent hierarchical properties- Since:
- 1.0
-
-
Method Details
-
properties
Retrieves the hierarchical properties for this workflow instance.- Returns:
- this workflow's collection of hierarchical properties
- Since:
- 1.0
-
start
Starts the execution of a new work instance.- Parameters:
klass- the work class whose instance that should be executed, the class should extendWork- Since:
- 1.0
-
start
Starts the execution of a new work instance.- Parameters:
work- the work that should be executed- Returns:
- this workflow instance
- Since:
- 1.0
-
inform
Convenience method that informs about an event in a workflow.- Parameters:
type- the type of the event- Since:
- 1.0
- See Also:
-
inform
Convenience method that informs about an event in a workflow with associated data.- Parameters:
type- the type of the eventdata- the data that will be sent with the event- Since:
- 1.0
- See Also:
-
inform
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
Convenience method that triggers an event in a workflow.- Parameters:
type- the type of the event- Since:
- 1.0
- See Also:
-
trigger
Convenience method that triggers an event in a workflow with associated data.- Parameters:
type- the type of the eventdata- the data that will be sent with the event- Since:
- 1.0
- See Also:
-
trigger
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
Causes the calling thread to wait until work is paused for events.This method also returns when no active work remains that could still pause, for instance when all work has finished or has failed with an exception. The returned value indicates which of the two situations occurred.
- Returns:
truewhen work is paused for events; orfalsewhen no active work remains that could still pause- Throws:
InterruptedException- when the current thread is interrupted- Since:
- 1.0
-
waitForNoWork
Causes the calling thread to wait until no more work is running.- Throws:
InterruptedException- when the current thread is interrupted- Since:
- 1.0
-
addListener
Adds a new event listener.- Parameters:
listener- the event listener that will be added- Since:
- 1.0
- See Also:
-
removeListener
Removes an event listener.- Parameters:
listener- the event listener that will be removed- Since:
- 1.0
- See Also:
-
addErrorListener
Adds a new error listener that will be notified when work fails with an exception.When no error listeners have been registered, work failures will be logged to the
rife.workflowlogger instead.- Parameters:
listener- the error listener that will be added- Since:
- 1.10
- See Also:
-
removeErrorListener
Removes an error listener.Once the listener has been removed, it will not be notified of any work failures anymore.
- Parameters:
listener- the error listener that will be removed- Since:
- 1.10
- See Also:
-