Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Now you certainly can use things like BPEL to solve these kinds of problems. However often this is a bit heavy weight & complex and you just want to have a bean based flow workflow using regular Java code to represent the flowactivities involved in the workflow.

Transforming the traditional workflow approach

...

Traditional approach

BeanFlow approach

use a declarative workflow definition language to specify a workflow

write a Java class

use workflow language to write loops, manage state, deal with persistence XML markup or pictures to define loops and flows

use regular Java code (if/for/while)

implement a generic state and persistence framework for workflow instances

use regular Java fields in your workflow class, then use JDBC/DAO/JPA to deal with persistence

...

Once a flow has been started via the start() method it can take an arbitrarily long time to complete; you can see if the flow has completed via the isStopped() method. You can explicitly complete a flow using the stop() method whenever you like; typically when you are responding to state changes.

A flow An activity could fail for some reason (such as it timed out or some error occurred) so there is a method isFailed() which can be used to easily inspect the flowactivity. Rather like the stop() method, you can call fail(reason) if you wish to terminate a flow an activity with the flow activity marked as the Failed rather than Stopped state.

...

Its very common to add timeouts onto flows activities so that if the flow activity is not complete by a certain time then the flow activity is stopped & failed; often another parent flow activity may then do something differently if one of its child flows activities fails.

There is a useful base flow activity called TimeoutFlow which you can derive from to make your own flow activity which can be started/stopped/failed and which can be timed out.

You can explicitly register the flow activity with a timer and call the onTimedOut() method yourself or just call the startWithTimeout() method to start the flow activity registering the timeout.

Join conditions

...

In BeanFlow we implement join conditions using regular Java code. The basic idea is that a Flow will listen to changes in a number of different State objects such as fields a, b and c. You can then write a flow an activity bean to perform the join condition you need. When the condition is met you can then perform whatever logic you wish such as

  • stopping the flowactivity
  • forking off a new child flowactivity
  • changing your state
  • changing the state of some other bean
  • calling arbitrary Java code

Here is an example flow activity implemented in Java code for the above code.

Wiki Markup
{snippet:id=join|lang=java|url=http://svn.apache.org/repos/asf/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/CustomJoinConditionTest.java}

Composing

...

activities

One of the main reasons for using an object orientated language is to make composition and reuse possible; similarly BeanFlow allows you to compose flows activities together to make modular and reusable workflow constructs easily. So BeanFlow attempts to create a collection of reusable flows activities which you can then use to derive from or aggregate to make whatever flows activities you need.

Composition Flows

Description

JoinAll

Performs a join on all the given child flowsactivities. So the flow activity waits until all the child flows activities have completed, then it completes itself. You can add additional constraints to the flow activity using derivation. The default is to wait for all the child flows activities to complete; though you can enable fast-fail mode so that the flow activity fails as soon as a child flow activity fails

JoinQuorum

This flow activity is useful for implementing clustering style flows activities where you want a quorum of flows activities to complete. e.g. if you have 5 child flows activities you want to wait for at least 3 flows activities to complete succesfully before continuing

...