Business state machines

A state machine is an event driven business application in which external operations trigger changes that guide the state machine from one discrete mode to another. Each mode is an individual state, and this mode determines what activities and operations can occur.

The WebSphere® Integration Developer tools have been designed so that users can easily compose integrative business solutions without programming skills. To this end, you can easily create and develop business state machines in an intuitive graphical programming environment called the business state machine editor.

Before you start to use this editor, you should browse these topics first:
Note: Business state machines can only be deployed to the WebSphere Process Server.

An example of a state machine

Let us begin with an example of a business state machine and see how it would be used to control the purchase of a can of soda pop from a vending machine.
Figure 1. A simple business state machine
An example of a state machine.

In the previous example, a user went through the appropriate steps to purchase a can of soda from a vending machine. The machine did not respond until money was deposited, and even then, did not proceed to the next state until the amount of money was sufficient. In each of the states in this example, the actions that the customer could perform were unique from any other state. For example, when it was in the primary state waiting for money, the customer could press buttons, but it would have no effect on the transaction.

Here are some basic terms that define the building blocks of business state machines:
States
A state is one of several discrete individual stages that represent a business transaction. Typically, it has this kind of life cycle:
  1. The state begins with the execution of any existing entry actions.
  2. The state will then stop and listen for an event to occur.
  3. When an event occurs, a path is chosen that is appropriate to it.
  4. An exit action (if there is one) is executed before the state machine transitions to another state.
Composite states
A composite state is an aggregate of two or more states. Use them to decompose a complex state machine diagram into an easy to comprehend hierarchy of state machines or to facilitate exception and error handling.
Events
An event is what triggers a transition from one state to another. In the case of call events, the events can have attributes. The attributes are the input parameters of the operation. If the transition has an action, these attributes are available to the action. An operation is just one type of event -- a call event. The other two that are currently supported are timer events and completion events.
Transitions
A transition is the movement that occurs through the recognition of an appropriate triggering event, the evaluation of the conditions necessary for execution to flow through it, and the determination of what actions can occur should execution be allowed.
A transition is triggered when its triggering event occurs, and it is enabled when the state machine enters the source state of the transition. Generally, a transition fires when it is enabled, triggered, and its condition evaluates to true. However, if the transition does not have a guard, then the first two conditions are sufficient.
Conditions
A condition guards the transition and only allows execution when and if it evaluates to 'True'. Otherwise the current state is maintained.
Actions
An action is an activity that is executed at one of three distinct locations within a business state machine:
  • on a transition
  • when a state is entered
  • when a state is exited

Correlations

Real life business transactions, such as the one shown above, can be modelled using a business state machine. The previous example was fairly simple, but in a typical business, the same type of business transaction will be repeated with multiple customers, often at the same time. With so much going on, it is easy to lose track of the status of these interactions, so the state machine uses correlation sets to distinguish the parties in their initial interaction so that they can recognize each other in the future. A correlation set is the record that is used to keep track of multiple participants in the same business transaction.

Consider the following example:
Figure 2. A business transaction that uses correlations to identify customers
A graphical example of the use of correlations

In this example, a customer goes to the vendor's store looking for a specific item that is ultimately sold out. Accordingly, the vendor issues a rain-check to the customer so that when there is sufficient stock, the customer can return and the vendor will be able to pick up the business transaction where it left off. The vendor is essentially assigning a token to the customer that is used to identify the customer when the transaction resumes.

It is important to note that the vendor is able to manage multiple tasks, and does not suspend business waiting for this one transaction to conclude. Instead, while they are waiting for the object to arrive, the vendor conducts similar business, using the same business process, with other customers.

Timeouts

A timeout is an expiration that is imposed upon a state. It is used to ensure that a state will not be maintained indefinitely while waiting for an operation that may never occur.

Consider this slight variation of the previous example:
Figure 3. An example of a timeout used with a business state machine
An example of a timeout used with a business state machine

In this version of the example, the completion of the state machine is interrupted by a lack of funds. The customer leaves to get more money, leaving the vending machine waiting in a single state. In this machine, a timeout duration has been set on this state, and after waiting in vain for a specified period of time, the existing money is returned, the current state is cancelled, and the machine returns to the initial state.

Feedback
(C) Copyright IBM Corporation 2005, 2007. All Rights Reserved.