Thursday, June 06, 2013

OSB-Parallel Programming with Static and Dynamic Split-Join

JAVA

In Java language, we can make one Thread to wait for another by using join method. 
private void startThreads(int nfOfThreads) {
  Thread[] threads = new Thread[nfOfThreads];
  //start the threads
  for (int i = 0; i < threads.length; i++) {
    threads[i] = new ThreadTestWithoutJoin.MyThread();
    threads[i].start();
  }
  //join the threads
  for (int i = 0; i < threads.length; i++) {
    try {
      threads[i].join();
    } catch (InterruptedException e) {}
  }
}

NOTE:
In the above code, there are two for-loops, the first to create and start each thread, and the second loop to join each thread. If each thread is joined right after start, the effect is these threads are executed sequentially, without the desired concurrency.
// The following is NOT concurrent:
private void threadTest(int numOfThreads) {
 Thread[] threads = new Thread[numOfThreads];
 for (int i = 0; i < threads.length; i++) {
     threads[i] = new foo.ThreadTest.MyThread();
     threads[i].start();
     try {
         threads[i].join();
     } catch (InterruptedException ignore) {
     }
 }
}
(Refer http://javahowto.blogspot.ca/2007/05/when-to-join-threads.html)

WLI

In WLI, Parallel node represents a point in a business process at which a number of activities are executed in parallel. By default, parallel nodes contain an AND join condition. In this case, the activities on all branches must complete before the flow of execution proceeds to the node following the parallel node. You can change the join condition to OR

NOTE:
Parallel branches of execution in a business process are logically parallel; physically the branches are executed serially by the business process engine. While one branch of execution is waiting for a response, another branch of execution in the parallel flow can progress.
(Refer http://docs.oracle.com/cd/E13214_01/wli/docs102/bpguide/bpguideParallelDesign.htmlhttp://docs.oracle.com/cd/E13214_01/wli/docs102/jpdtutorial/tutWLIProcessParallel.html)

OSB

In OSB, Split-Join feature lets you split a service payload, such as an order, into individual messages for concurrent processing. Concurrent processing, as opposed to sequential processing, greatly improves service performance. Split-Join achieves this task by splitting an input message payload into sub messages (split), routing them concurrently to their destinations, and aggregating the responses into one overall return message (join). This process of payload splitting and response aggregation is called a Split-Join pattern.we can create Split-Join flow for parallel programming. There are two types of Split-Join, one is static and another one is dynamic.

The Static Split-Join can be used to create a fixed number of message requests
The Dynamic Split-Join can be used to create a variable number of message requests.

Any webservice needs a WSDL, Split-Join flow is the same and the first thing we need to do is to create a WSDL. Every Split-Join is based upon a WSDL operation. When you first create a Split-Join, you will be asked to browse to the appropriate WSDL file and to select an operation as part of the creation process. The WSDL of Split-Join flow can be same as the proxy service which will invoke the flow or you can defined a totally different WSDL. The choice is really based on your requirement.

For dynamic Split-Join, please refer the follow blogs. As these blog is pretty detail, I won't write anything.
http://biemond.blogspot.ca/2008/11/split-join-in-oracle-service-bus.html
http://www.xenta.nl/blog/2011/07/03/oracle-service-bus-implementing-aggregator-pattern-by-use-of-split-join/
http://rohanlopes.blogspot.in/2011/10/implement-parallel-split-join-osb.html

For static Split-Join, I got few help from the internet. But it is pretty easy when you have done a dynamic one.
First, create a new Split Join based on the WSDL operation you want to use.  In the Split-Join editor, you can see following flow, which consists of a Start Node, a Receive, a Reply. By clicking the triangle icon beside of Start Node, you can see the Start Node contains both a Request Variable and a Response Variable that have been determined by the WSDL operation initially selected. You can change the variables' name same as what you did in dynamic Split-Join. The Receive Node receives the incoming request message, and the Reply Node generates a response message and sends it back to the client.
Debugging a proxy service
Second, add an Assign Node after the Receive Node to initialize the Response Variable in a form such that the later nodes can work on the data within it. This output message is relayed to the final Reply node in the Split-Join and, in turn, returned to the original client.
Third, add a Parallel Node. The Parallel Node contains two main branches at the beginning, you can add more by clicking on the plus icon. Each branch is composed of a number of actions, the sequence and general configuration being the same for both branches.
Debugging a proxy service

Forth, add an Invoke Service Node. On the properties tab, config the service and operation. Select the Input Variable to create a new request variable and then select the Output Variable to create response variable. The result will be stored in the output Variable. The service you reconfigured for each branch may be not the same based on your requirement.

Fifth, add an Assign/Copy/Insert/Replace before the Invoke Service Node to prepare the input variable for service invocation. As the service invoked may be different, the logic in the node is not the same.

Sixth, add an Assign/Copy/Insert/Replace after the Invoke Service node to put the data in the Output Variable to the response variable of flow.

When you done everything you need, you can follow the steps in dynamic Split-Join to generate a business service. Then you can invoke it and test it in a proxy service.

If you have the book The Definitive Guide to SOA, you can look at the chapter 7 Parallel Calls with Split-Join for help as there is more detail.
(Reference http://docs.oracle.com/cd/E13159_01/osb/docs10gr3/eclipsehelp/tasks.html#wp1150654)

When I opened the source code of flow in text editor, I found the flow is implemented with BPEL instead of genera OSB xml.

1 comment:

GenericParallel said...

Note that there is a convenient wrapper over Split-Join - the GenericParallel library - which not only makes things way easier, but also fixes some known shortcomings of Split-Join. It is free and open-source.