Chapter 22. HowTo - Combine multiple connectors

It is possible to combine several connector-instances to one parent connector that appears to workflows like any other connector. For example you may want to have several notification-connectors in a workflow. It uses the location-placeholder "foo". So when the workflow expects the connector-instance at location "foo", you may want it to call multiple connectors. One would expect that simply assigning the location "foo" to every connector would create this behaviour, but it doesn't. By default, the connector with the highest service ranking is chosen (see OSGi-core-specification section 5.5.5).

22.1. Composite strategies

There are also other issues with using multiple service in a place where one single service is expected:

  • Should the services be called concurrently or sequentially?
  • Which service should be called first?
  • What should be returned as a result?

All this is specified by a CompositeStrategy. Strategy-implementations must implement the CompositeConnectorStrategy interface and be registered as OSGi-services exporting this interface. Also the service must specify the "composite.strategy.name" property. The strategy is provided with a list of ServiceReferences, and the invocation parameters. The implementation can decide which services to resolve and to invoke. Also the strategy must return a single result.

22.2. Create a composite connector

A composite connector instance can be created like a regular connector-instance. You need to supply the following attributes:

  • querystring: a string representing an OSGi-query. All services that match this query are passed on to the strategy as ServiceReferences. Example: Suppose we have two notification services. One has the property location.foo=notification/1 and the other one has location.foo=notification/2. A possible query-string for the composite-service could be (location.foo=notification/*).
  • composite-strategy-name: The name of the strategy that should be used.