4.5. Service Factory

We have seen that after a bundle registers a service, other bundles can use it. So far, all client bundles are using the same instance of the service. Many applications may find this arrangement lacking under the following circumstances:

  • A service-providing bundle may want to provide different instances of a service based on which bundle makes the request. This allows a customized service to be returned for each caller.

  • A service-providing bundle may need the opportunity to perform application-specific logic when a client bundle gets or releases the service.

A service factory can address these issues. We illustrate how to write a bundle that registers a service factory through an example.

4.5.1. Producing a Customized Service ...

Get Programming Open Service Gateways with Java Embedded Server™ Technology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.