tcalmant / ipopo

iPOPO: a Service-Oriented Component Model for Python
https://ipopo.readthedocs.io/
Apache License 2.0
69 stars 28 forks source link

Add support for ServiceFactory #75

Closed tcalmant closed 6 years ago

tcalmant commented 7 years ago

Even if they have been less than 10 answers to the usage survey, the most requested feature is the support for Service Factories.

A Service Factory is a special kind of service that is called by the framework each time it is requested by a bundle: this allows to have one instance (or even implementation) of a service per bundle. The methods called by the framework are get_service(bundle, service_registration) and unget_service(bundle, service_registration, service_object). The concept of service factory is defined in the OSGi Core Specification, section 5.9, page 140 (for version 6.0).

The OSGI specification also defines the concept of Prototype Service Factory (section 5.10, page 140) which allows to have multiple service objects, even for the same bundle. It uses the same un/get_service() methods as the service factory. This concept also adds a ServiceObjects interface, retrieved with the BundleContext.get_service_objects(service_reference)method (see section 10.1.7.14, page 205).

Both concepts requires the addiction of the concept of service scope (section 5.3, page 134) and to review the way get_service() works, to follow the rules of section 5.4, as Pelix supports only a part of it.

As a result, this feature will come after the following steps:

tcalmant commented 7 years ago

ServiceFactory feature has been merged in the master branch. The PrototypeServiceFactory is still to be developped, but might be added in 0.6.6 instead of 0.6.5.

tcalmant commented 6 years ago

PrototypeServiceFactory have been implemented successfully. Tests have been added to check their behaviour and to validate that the ServiceObjects API works as described in the OSGi specifications.

A new feature has been added in order to have a sane behaviour: service auto-release. When a consumer bundle stops, the framework now ensures that all the services it uses are released. This doesn't mean you can avoid explicit releases, this is mainly a feature to keep a clean state even when a bundle activator fails when the bundle is stopping.

tcalmant commented 6 years ago

Documentation has been added, so this issue can be closed. Please open a new issue if a bug is found in the implementation.