-
Notifications
You must be signed in to change notification settings - Fork 216
defining workflow
A work flow in Easy Flows is represented by the WorkFlow
interface:
public interface WorkFlow extends Work {
}
A workflow is also a work. This is what makes workflows composable.
Easy Flows comes with 4 implementations of the WorkFlow
interface:
A conditional flow is defined by 4 artifacts:
- The unit of work to execute first
- A
WorkReportPredicate
for the conditional logic - The unit of work to execute if the predicate is satisfied
- The unit of work to execute if the predicate is not satisfied (optional)
To create a ConditionalFlow
, you can use the ConditionalFlow.Builder
:
ConditionalFlow conditionalFlow = ConditionalFlow.Builder.aNewConditionalFlow()
.named("my conditional flow")
.execute(work1)
.when(WorkReportPredicate.COMPLETED)
.then(work2)
.otherwise(work3)
.build();
A SequentialFlow
, as its name implies, executes a set of work units in sequence. If a work unit fails, next work units in the pipeline will be skipped. To create a SequentialFlow
, you can use the SequentialFlow.Builder
:
SequentialFlow sequentialFlow = SequentialFlow .Builder.aNewSequentialFlow()
.named("execute 'work1', 'work2' and 'work3' in sequence")
.execute(work1)
.then(work2)
.then(work3)
.build();
A parallel flow executes a set of work units in parallel. The status of a parallel flow execution is defined as:
-
WorkStatus#COMPLETED
: If all work units have successfully completed -
WorkStatus#FAILED
: If one of the work units has failed
To create a ParallelFlow
, you can use the ParallelFlow.Builder
:
ExecutorService executorService = ..
ParallelFlow parallelFlow = ParallelFlow .Builder.aNewParallelFlow()
.named("execute 'work1', 'work2' and 'work3' in parallel")
.execute(work1, work2, work3)
.with(executorService)
.build();
executorService.shutdown();
NB: It is the responsibility of the caller to manage the lifecycle of the executor service.
A RepeatFlow
executes a given work in loop until a condition becomes true
or for a fixed number of times. The condition is expressed using a WorkReportPredicate
. To create a RepeatFlow
, you can use the RepeatFlow.Builder
:
RepeatFlow repeatFlow = RepeatFlow .Builder.aNewRepeatFlow()
.named("execute work 3 times")
.repeat(work)
.times(3)
.build();
// or
RepeatFlow repeatFlow = RepeatFlow .Builder.aNewRepeatFlow()
.named("execute work forever!")
.repeat(work)
.until(WorkReportPredicate.ALWAYS_TRUE)
.build();
Those are the basic flows you need to know to start creating workflows with Easy Flows.
You can create your own flows by implementing the WorkFlow
interface.
The WorkFlowEngine
works against interfaces, so your implementation should be interoperable with built-in flows without any issue.
-
Introduction
-
User guide
-
Get involved