As with all the other gateways that we've seen till now, the complex gateway involves a split activity which can be either an inclusive gateway (see "Inclusive and Complex" pattern) or an exclusive gateway and a complex merge gateway (see "Parallel and Complex" pattern).
Similar to an inclusive gateway, a process implementing the "Inclusive and Complex" pattern will follow all conditional paths whose expressions are evaluated to true. All conditional expressions that evaluate to true are executed; otherwise the default sequence flow is executed.
|"Inclusive and Complex" pattern|
|"Parallel and Complex" pattern|
When a process reaches a complex gateway activity it will create a token for each outgoing sequence flow that evaluates to true. You can configure the complex gateway merge activity to continue execution even if not all of the tokens have arrived at the complex gateway merge activity. For example, if you have three parallel sequence flows executed you can configure the complex gateway to continue after two or more tokens have arrived at the merge activity. This is really handy when you want to implement a voting based pattern on process activities.
Let's see how you can use the complex activity in a demo process. I will base my demo on the process I created in part three of my five-part series, Oracle BPM 12c Gateways (Part 3 of 5): Parallel Gateway. Let's assume that you are implementing an order process and that at some point in your process you want to request for quotations from three different suppliers. Your process shouldn't wait for a response from all three suppliers; it is sufficient that you receive quotations from just two suppliers. Once you have received quotations from any two out of the three suppliers your process should continue (ideally pick the lowest quotation but I will not be implementing this part).
So let's start with creating a BPM application with a default BPM project (named both application and project "ComplexGatewayDemo") having an empty composite.
Since I want to send a request to all three suppliers I will change the complex gateway pattern to "Parallel and Complex". You can do so by right-clicking on the inclusive split activity and choosing from the context menu "Change Gateway configuration to -> Parallel and Complex".
There is a special predefined variable in a complex gateway called "activationCount" that will return you the number of tokens that have arrived to the merge gateway. You can use this with other custom data objects to form complex expressions.
In my demo, I only care for any two quotations so I will just use the activationCount variable to count the number of tokens that have reached the complex gateway. If two or more tokens have reached the complex gateway merge activity then my process shouldn't wait for the third token but instead continue with its execution.
If you go back to the flow trace you should see that all three human tasks have been completed and the process ended.
Download sample application: Complex Gateway