Using Complex Gateways in Oracle BPM 11g
March 14, 2012
Starting here and in some of the forthcoming blog posts I will try to cover some basic and advanced gateway patterns in Oracle BPM Suite 11g.
This post shows how and in which scenarios do we need to use a Complex Gateway in a business processes modeled with BPMN techniques.
Complex Gateways are required to synchronize N paths from M incoming transitions. This gateway is a point in the process where M parallel (or inclusive) branches converge into it and the following activity is enabled once N incoming branches have been triggered (or their outcomes met). The result of the rest of the M minus N branches is ignored. The merge is blocked till the M incoming branches have been triggered and unblocked when their execution is completed.
Complex Gateways are rare in business process modeling but very essential to realize some very common workflow patterns. Consider for example a widely used modeling technique that supports explicit skipping of activities. Imagine how you use an OR gate to write conditions to negate the sequences that you don’t want to be executed.This is commonly referred to as dead path elimination. However, the OR join cannot be applied in all cases of dead path eliminations. The complex gateway is intended to model complex synchronization behavior. In general,firing behavior of the complex gateway is specified using an activation expression which is evaluated with the reception of every token. It might reference separate token counters for each of the directly preceding sequences. Once the activation expression evaluates to true, a token is created on the normal output flow. The gateway is also capable of aborting all pending flows and finally resets by creating a token on the optional reset output flow.The Use Case
To process a security clearance application, a business process needs to check concurrently whether the applicant has a criminal record, is a natural citizen, and has sound credit history. The outcomes of these checks is to be evaluated in such a way that as soon as two of these checks pass and the applicant doesn’t have any criminal history, a clearance is granted, and the third check is aborted. This pattern, a special case of the N/M join.
The Security Clearance Process has three sub processes Criminal Record Check, Natural Citizen Check, and Credit History Check that are run in parallel (having been launched by the AND parallel split from Initiate Security Checks). There is also a special complex gateway element (diamond with an asterisk) to evaluate the outcome of responses coming from each of the sub processes. This is a typical example of a 2 of 3 join with one precise condition to be met.
The prerequisite to create and use the business process explained in this post you would need Oracle SOA Suite 11g PS4 or higher.
Modeling the Process
Let me begin with trying to model the business process as shown above in JDeveloper BPM Studio. It involves creating a composite project with BPMN extension and then creating a BPMN process with an asynchronous interface. The start event is a message start type that accepts personal information header to be able to process security clearance for an individual.
The next step involves creating a gateway of complex type in the business process and changing its type to “Parallel and Complex”. From the parallel arm create three sub processes that converge to the gateway merge.
Each of the sub processes are implemented to invoke a service that takes in the personal information of an individual and returns a corresponding response. For example, there is a criminal check service that returns the crime history and all available crime records for an individual based on his SSN. These services are mocked to be able to execute the process and are packaged in a WAR file (Complex Gateway Services).
The way i chose to implement each of the sub process is decouple them from the validation services totally. Raise an event to check an individual’s crime history and then let another process subscribe to it (implemented with BPEL). The BPEL process then invokes any number of services to gather the crime records and finally publishes a status event by itself too. The original sub process then have an intermediate mid process receive event that subscribes to the validation status, correlates and ends. Don’t worry too much if you do not get what is explained. You can import the process (application) being discussed from the link here.
The GetCrimeHistory mock service is returns a list of criminal records (if they exists) and a Boolean flag called recordExists (true if SSN begins with 1, false otherwise).
The other two sub processes are implemented in the exact way, only they invoke a different set of services to check the status of citizenship and obtain a credit history for an applicant.
What is of typical importance is the Gateway Merge point that evaluates the outcome/results of these sub processes. Now as per the use case, there are two checks to be evaluated to go ahead further down the process, 1.) confirm whether there is any record of crime existing for the applicant 2.) get a valid approval check response from either the credit history check or citizenship status check sub processes.
The first condition is enforced with the expression crimeSummary.recordExists==false. The logic for the second condition is provided by checking the value of the activationCount variable (predefined). This variable holds the value of tokens being received at the merge gateway. As per the expression below, if at least two tokens are received then the process is good to move ahead. The checkbox to Abort pending flows ensures that when the flow control moves ahead after receiving the required tokens, all pending sequence flows are abruptly cancelled (This can be perceived as dead path elimination without writing a negation condition on any of the sequence flows).
Deploy the completed process to the BPM infrastructure as a composite application. From the Enterprise Manager console navigate to the deployed composite dashboard. Since the business process had a message start event, it can be exposed as a standard service. The Test button on the composite dashboard can be used to test the composite application.
Test 1 : Criminal Record is Present
Create a test request for the composite operation so that the criminal record status flag is returned to be true(Value of input SSN to begin with 1). Invoke the service and wait to let the execution complete. Lunch the audit trail to analyze what happens and how does the gateway evaluates the sequences.
The process executes in entirety and is successfully completed. However to examine the behavior of the gateway we would need to see the instance flow trace of the BPMN component.
The Intiate Security Checks gateway is denoted as a parallel splitter and spawns three independent threads to executes sequences originating from it concurrently. The event status of each of the thread is Thread Completed. Wonder why all the three threads executed when the gateway merge was supposed to get going even when two tokens were sufficient? Well this is because the gateway expected a true value of crime summary flag. Since the flag returned was false, it lets all sequences complete in the hope that it may receive a true flag from may be some other sequence.
Lesson Learnt : It is important to design your Complex Gateways effectively in order for them to function in a true N/M way. If you put more restricting conditions, it might as well behave as a normal split-join one.
Expand the merge gateway marked as Clearance Checks and see the XML payload. Every time a sequence flow is executed and it reaches the gateway merge the gateway exit expression is evaluated.
The first evaluation has to always fail since the merge needs at least two tokens. If the second token arrives from the Crime Check sequence, the merge gateway is again evaluated. The first condition is met as two tokens have arrived but since the a criminal record exists, the expression again evaluates to false. The flow cannot move forward since another sequence is still being executed (which eventually again will not meet the second condition in the expression).
Now assuming if the process is tested in such a way this time that the response of the Criminal Check sub process evaluates to a false (SSN value not starting with 1), the execution trace of the instance will be starkly different from the case above. Look into the BPMN flow trace, and this time you may very well find that the merge gateway goes ahead just after getting tokens from any two sequence flows. And the pending sequence is cancelled as the gateway expression has evaluated to true. In the instance execution trace being shown below carefully examine how the Credit Check thread is marked as Cancelled as the flow result evaluates to true. This is pretty neat as the process was able to successfully implement a N/M dead path elimination using a complex gateway (depending on sequence execution outcome).
This concludes this article that explains the usage of complex gateways in Oracle BPM Suite 11g. In the forthcoming posts, I shall describe other patterns and usage of Event based gateways.More Relevant Use Cases
Now if you are wondering whether the example used in this post is too hypothetical and there would seldom be a case or a need in your business process to have a complex gateway that eliminates dead paths depending upon outcomes rather than negation logic in the flow sequences. Perhaps it is time to think over.
Imagine the scenario explained above, arising when a business process is trying to orchestrate Order booking. The process is initiated with order headers and the business it needs to fetch customer data and order details to continue processing. The customer information may be available in an intermediate cache or certainly in the master customer data hub.
See how again using a complex gateway in this scenario is helpful!
The Source Code and Relevant FilesThe JDeveloper application used in the article can be downloaded from the link contained here.