public interface ServiceFactory
Service factories allow services to provide customized service objects. In order to gain control over the specific service object given to a bundle using the service, a bundle programmer can register a ServiceFactory object instead of a service object when registering a service.
When this is done, the BundleContext.getService(ServiceReference) method calls the service factory's getService(Bundle, ServiceRegistration) to create a service object specifically for the requesting bundle. The service object returned by the service factory is cached by the framework until the bundle releases its use of the service.
When the bundle's use count for the service drops to zero (including the bundle stopping or the service being unregistered), the service factory's ungetService(Bundle, ServiceRegistration, Object) method is called.
ServiceFactory objects are only used by the framework and are not made available to other bundles.
Member Summary | |
---|---|
Methods | |
public Object | getService(Bundle, ServiceRegistration) |
Create a service object. | |
public void | ungetService(Bundle, ServiceRegistration, Object) |
Release a service object. |
public java.lang.Object getService(Bundle bundle,
ServiceRegistration registration)
Create a service object.
The framework invokes this method the first time a given bundle requests a service object using BundleContext.getService(ServiceReference). The factory can return a specific service object for each bundle.
The framework caches the value returned (unless it is null), and will return the same service object on any future call to BundleContext.getService (ServiceReference) from the same bundle.
The framework will check the returned service object. If the service object is not an instanceof all the classes named when the service was registered, null is returned to the bundle.
Parameters:
Returns: A service object that must be an instanceof all the classes named when the service was registered,
public void ungetService(Bundle bundle,
ServiceRegistration registration,
java.lang.Object service)
Release a service object.
The framework invokes this method when a service has been released by a bundle. The service object may be destroyed at this time.
Parameters:
bundle—The bundle releasing the service.
registration—The ServiceRegistration for the service.
service—The service object returned by a previous call to getService(Bundle, ServiceRegistration).
13.58.209.201