Implementing an Asynchronous Business Process

The implementation for the asynchronous business process is a modification of the simple business process presented in Chapter 8, "Exploring the Business Process Pattern." The interface to the BusinessProcess now includes the following:

  • The return of a unique identifier when a client starts a business process

  • The addition of interfaces to monitor attributes of the business process, including the status, given the unique identifier

Figure 9-4 illustrates the modifications to the business process. In addition to the updated interface, there is a new class, ProductOrderManager , which serves as the interface to the Web Service. The business process class, ProductOrderImpl , implements the java.lang.Runnable interface as it runs in its own thread in the Java platform.

click to expand
Figure 9-4: Asynchronous product ordering business process

Rather than having a client block until the process is complete, the client application returns from the Web Service call quickly, but it must maintain a durable unique identifier for later use. Because of this requirement, the business process invocation cannot be a completely asynchronous call because the service implementation generates the unique identifier, not the Web Service environment. Future client-invoked operations use the unique identifier to query the business process for a specific attribute ”in this case, the status of the business process.

Starting a Business Process

In the case of the business process for ordering products, the unique identifier to the business process is the key to an OrderImpl business object. The CreateOrder business activity creates the order instance that, in turn , returns a unique key to the ProductOrder business process. The ProductOrder business process passes this key on to the ProductOrderManager instance that, in turn, returns the key to the client. For this particular asynchronous business process, the OrderImpl business object serves as the location to retrieve process state; thus, the OrderImpl represents the ProcessState design component. Figure 9-5 shows this sequence of collaborations.

click to expand
Figure 9-5: Sequence diagram for the product order asynchronous business process

The primary difference between the invocation of the business process in this chapter and the one in the previous chapter is that this implementation returns to the client before the entire business process completes. The client then needs to save the unique identifier to the business process to check on the business process later. You are also calling the new Web Service interface, the ProcessOrderManager , though it is simply an evolution of the ProcessOrder Web Service from the previous chapter. The ProcessOrder business process itself still plays an important role as an internal implementation class.

Listing 9-1 shows the invocation of the business process through the architecture adapter representing the ProcessOrderManager to the Java client. The unique identifier returned from the start of the business process gets stored in a local instance variable for use later in the client application.

Listing 9-1: Invocation of an Asynchronous Business Process
start example
 ProductOrderManagerService service =   new ProductOrderManagerServiceLocator(); ProductOrderManager port = service.getProductOrderManager(); String customer = "1035664203330"; // id of paul monday String productSkus[] = {"1035664206840"}; // id of French roast int quantity[] = {2} String jobIdentifier = port.createProductOrder(   customer,   productSkus,   quantity); 
end example

Interestingly, the client's usage of a local instance variable for the process identifier storage creates a problem. Once the client exits, it will be difficult to locate any business processes that the client kicked off. There are several ways to deal with this situation. In the event that the client is a browser-based client, a cookie should be stored on the client that a server-side process can recover when the client reconnects. A specific mechanism for retaining process identifiers is outside of the scope of this book.

Querying Business Process Attributes

Once the client starts the business process, the client uses the unique identifier, saved as part of the creation process, to query various attributes of the business process. Figure 9-6 illustrates an application retrieving the status of the product order placed in the previous section, "Starting a Business Process."

click to expand
Figure 9-6: Querying the status of a product order

The Java client simply uses an architecture adapter to the ProcessOrderManager WebService. The code reuses the jobIdentifier variable from Listing 9-1, as well as the port instance variable referring to the Web Service:

 int jobStatus = port.getStatus(jobIdentifier); 

There is one major loose end in the previous code ”interpreting the status returned by the operation. There are varieties of ways to solve this problem, but they are all variations on the same theme: provide a robust enough contract for potential clients to interpret the return codes.

Web Service Patterns
Web Services Patterns: Java Edition
ISBN: 1590590848
EAN: 2147483647
Year: 2003
Pages: 190

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: