Orchestrating Processes with Asynchronous Events

While describing our business scenario, we mentioned that the handleApprovedOrder method of the SupplierProcess activity is initiating an entirely different process between the Supplier and a specific Manufacturer, AndyNailsProcess (see Figures 10-28 and 10-29). In fact, this was both an over- and an understatement at the same time.

It is an overstatement because SupplierProcess does not directly initiate any other processes. It is an understatement because indirectly it may initiate an arbitrary number of the processes—as many as will be willing to listen to the event.

Meet asynchronous events: SupplierProcess simply broadcasts an event per each line of the approved retailer order, as shown in Example 10-34.

Example 10-34. Fragment of SupplierProcess related to dispatching events

public int handleApprovedOrder( String orderId ){
   OrderLineItemDAO orderLineItemDao = new OrderLineItemDAO();
   List<OrderLineItemDTO> orderLineItems = orderLineItemDao.getLineItems(
      orderId
   );
   for ( int i = 0; i < orderLineItems.size(); i++ ){
      OrderLineItemDTO lineItem = orderLineItems.get(i);
      EventsHelper.dispatchLineItemEvent(
         lineItem.LINEITEM_ID, lineItem.MNF_CODE);
   }
   return ORDER_STATUS_APPROVED;
}

How are the processes are being set up to “wake up” based on the broadcast event, and what does it take to actually dispatch these events? These are the topics of the next section.

Defining Events

Asynchronous events look and act much like network messages. They ...

Get Agile Enterprise Application Development with Flex now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.