ServiceFactory

Syntax

public interface ServiceFactory

Description

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 ObjectgetService(Bundle, ServiceRegistration)
 Create a service object.
public voidungetService(Bundle, ServiceRegistration, Object)
 Release a service object.

Methods

getService(Bundle, ServiceRegistration)
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:

bundle— The bundle using the service.

registration— The ServiceRegistration for the service.

Returns: A service object that must be an instanceof all the classes named when the service was registered,

See Also: BundleContext.getService(ServiceReference)

ungetService(Bundle, ServiceRegistration, Object)
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).

See Also: BundleContext.ungetService(ServiceReference)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.174.23