jBPM4 real-life example: The Train Ticket Demo (part 5: BI and BAM)

Business processes are never finished

As a business changes or grows, business processes will need to incorporate these changes or they will become a drawback for the business. There are the natural changes that come as the business or the market change, but some changes are related to the actual feedback that is received from measuring metrics about the business process executions.

If you take a look at the BPM lifecycle, gathering this feedback means that the process executions must be monitored. Using the metrics gathered there, it will be possible to discover bottlenecks in the process (eg some task is taking long due to a human resource problem) and to act upon them. The next step will then be optimizing the business process, with the new knowledge as background. Now, the lifecyle is completed and we’re back to modeling the actual changes in the process in our BPMN Signavio editor. So, as a developer, it might be interesting investing in jBPM, since your work will never be done (this applies certainly for contractors ;-))

Traditionally, there are two concepts that are often used when one discusses ‘monitoring’ business processes. I’m talking here about Business Intelligence (BI) and Business Activity Monitoring (BAM). Typically, BI is used when the data that is used is historical (eg. monthly reports), whereas BAM is used when the data is real-time. Often, BAM is coupled with Complex Event Processing (CEP) to allow for automatic actions that are triggerd once a certain event or pattern is discovered. Yes, I know these are lot of fancy words, but they all come down to one thing: displaying data of business processes in some way or another.

In this article, I’ll demonstrate how BI and BAM can be done with jBPM. Today, I also have 2 screencast for you, so be sure to read the article to the end (which should be the case anyway 😉 )

Business intelligence with jBPM

I’ve already discussed this topic in a previous article, so I’ll be short here. Using the jBPM console, it is very easy to write your own BI reports and display it in the console. Since we are using the Eclipse BIRT engine, this means that the reports are also usable without the console or embedded within your own application. Take a look at the following screencast, where two things are shown:

  • The cellhone emulator (aka the jBPM-phone) is used to send text messages to the Ticket Handling Platform and the jBPM console is used to inspect the actual process instances.
  • The default BI report is rendered and displayed through the jBPM console.

Business activity monitoring with jBPM explained

For implementing BAM, we’ve used a setup as displayed in the following picture (click for bigger version):

Conceptually, the story goes as follows: inside the process, events (= pojos) are fired to a JSM queue. On this JMS queue, a message driven bean is parsing the events and handing them over to a CEP engine. In the demo, we are using the Esper engine, wrapped in an EJB3 such that the CEP handling scales with our existing architecture. Depending on the type of event, Esper will execute an action by invoking a so-called Subscriber. In our demo, this is mostly writing aggreagations to the database.

Note that this way of working is based upon the ideas from the book ‘Open Source SOA’, by Jeff Davis. Which also includes two big chapters about jBPM, by the way.

We’ll now look more closely into how this is actually done in Java code:

On certain activitites, we define an event listener. In the following example, we listen to the ‘end’ event of the ‘chargecustomer’ activity and send an event using the SendEventToQueue handler class. Also note that the event is send asynchronously, which means that the actual sending of the message is not done in the original thread. This way, the response towards the customer can be send more quickly.

<custom name="charge customer ...">
  <on event="end" continue="async">
      <field name="eventClass">
        <string value="org.jbpm.trainticketdemo.event.TicketSoldEvent"/>
      ... (more fields, see source for details)
  <transition to="end"/>

The TicketSoldEvent that is fired here, is just a regular pojo:

public class TicketSoldEvent implements Serializable {

  private String from;

  private String to;

  private Double amount;

  // getters and setters


These events are received by a message driven bean and handed over to the Esper runtime engine (see line 17):

@MessageDriven(activationConfig =
 @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
 @ActivationConfigProperty(propertyName="destination", propertyValue=JmsConstants.EVENT_QUEUE)
public class EventQueueProcessor implements MessageListener {

 // field declarations omitted

  public void onMessage(Message message) {

    try {
      if (message instanceof ObjectMessage) {

        ObjectMessage objMsg = (ObjectMessage) message;
        Object obj = objMsg.getObject();

    } catch (JMSException e) {

Without going into much details about Esper (read their excellent documentation if you are interested). We use Esper in the demo to cope with ‘pojo streams’. These pojo streams can be aggregated and queried upon using regular SQL, which I think is really cool:

EPStatement moneyTracking = admin.createEPL(
 "select count(*) as nrOfTickets, sum(amount) as total, " +
 "avg(amount) as average, stddev(amount) as stddev " +
 "from TicketSoldEvent.win:time(15 sec)");

 moneyTracking.setSubscriber(new MoneyTrackerSubscriber());

Note that we are selecting here the count, sum, average and standard deviation aggreagtion of the ticket sale data, based upon the TicketSoldEvent pojos that were received during the last 15 seconds. The results of that query are handed over to another pojo, the MoneyTrackerSubscriber, which will just store this results in the database for displaying them in the GUI.

Note that we are barely scratching the power of Esper here. It is for example also possible to join pojo streams, based on pojo field values. Take for example a look at the following snippet, where we join the TicketRequestReceived event with the QuoteSentEvent which have the same processInstance id, to calculate the time between receiving a cellphone text message and actually replying on it (which might be an SLA).

// SLA for the time between the ticket request receival and the quote sending
 EPStatement responseTimings = admin.createEPL(
 "select TicketRequestReceivedEvent.timestamp as ticketRcvTime, QuoteSentEvent.timestamp as quoteSentTime, " +
 "TicketRequestReceivedEvent.processInstanceId as processInstanceId " +
 "from TicketRequestReceivedEvent.win:time(24 hours) inner join QuoteSentEvent.win:time(24 hours) " +
 "on TicketRequestReceivedEvent.processInstanceId = QuoteSentEvent.processInstanceId");

But you can go much further with Esper. I particulary like the pattern detection mechanism for streams. I’ve used it in the past a lot, for example to build a fraud-detection system: when a certain pattern in the events is found (I believe it had to do with money that was first refused and than we checked on events that were related to the same customer trying to get smaller amount of money approved), an email would be send out to all the account managers involved. But such features are probably for a next iteration of the demo. By that time, we might be able to leverage the SAM solution which Heiko described in a blogpost.

Bam: The end result

The following screencast shows the end result of the explanation of the previous section. The data that is gathered by the subscribers of our events, are displayed using a Seam application, with Richfaces for the general GUI and Primefaces for the flash chart rendering. Using some ajax magic, the charts are rerendered in real-time.

The demo BAM application shows following information:

  • The average and standard deviation time between receiving the text messga eand sending a response (SLA)
  • The time it took the customer to respons with an ‘accept message’, shown as a pie chart with catagories (eg < 30 seconds)
  • The number of customers who had enough money on their balance vs those who didn’t
  • The total money earned (with average and stddev)  in the last 10 windows of 15 seconds

It is easy to see how the information from the BI reports and the BAM application can be used to enhance the business process. Eg when a lot of customers aren’t able to pay because they forgot to add money to their account, it could be wise to add a step to the process that ask ‘do you want to add more money?’, using the credit card registered with the customer. So, your imagination is the only limiting factor here 😉

Like before, the source code can be found in our svn repo:


  1. Eduardo September 18, 2009


    very interesting this demo. I have a app that enable any celphone execute activities, but in Oracle BPM server!

    See this!

    xBPM is a little diferent, because has a client for execute tasks and not for SMS! But the idea is the same, make mobility in process management!


  2. Joram Barrez September 18, 2009

    @Eduardo: nice demo! Is xBPM tied to Oracle or is it BPM product agnostic?

    We did something similar a few months ago, using a bluetooth client and a JME app on the phone: http://www.jorambarrez.be/blog/2009/05/13/jbpm-community-day-2009-retrospective/

  3. Abhishek October 21, 2011

    Great post. For those who are interested in checking out JBPM5, You can Try JBPM5 on BPMGeek.com. Live standard install

Leave a Reply

Your email address will not be published.