ServiceRegistration

Syntax

public interface ServiceRegistration

Description

A registered service. The framework returns a ServiceRegistration object when a BundleContext.registerService(String[], Object, Dictionary) method is successful. This object is for the private use of the registering bundle and should not be shared with other bundles.

The ServiceRegistration object may be used to update the properties for the service or to unregister the service.

If the ServiceRegistration is garbage collected the framework may remove the service. This implies that if a bundle wants to keep its service registered, it should keep the ServiceRegistration object referenced.

Member Summary
Methods
public ServiceReferencegetReference()
 Returns a ServiceReference object for this registration.
public voidsetProperties(Dictionary)
 Update the properties associated with this service.
public voidunregister()
 Unregister the service.

Methods

getReference()
public ServiceReference getReference()
            throws java.lang.IllegalStateException

Returns a ServiceReference object for this registration. The ServiceReference object may be shared with other bundles.

Returns: A ServiceReference object.

Throws:

javalang.IllegalStateException— If this ServiceRegistration has already been unregistered.

setProperties(Dictionary)
public void setProperties(java.util.Dictionary properties)
            throws java.lang.IllegalStateException

Update the properties associated with this service.

The key “objectClass” cannot be modified by this method. Its value is set when the service is registered.

The following steps are followed to modify a service's properties:

 
1.
The service's properties are replaced with the provided properties.

2.
A ServiceEvent of type ServiceEvent.MODIFIED is synchronously sent.

Parameters:

properties— The properties for this service. Changes should not be made to this object after calling this method. To update the service's properties this method should be called again.

Throws:

javalang.IllegalStateException— If this ServiceRegistration has already been unregistered.

unregister()
public void unregister()
            throws java.lang.IllegalStateException

Unregister the service. Remove a service registration from the framework's service registry. All ServiceReference objects for this registration can no longer be used to interact with the service.

The following steps are followed to unregister a service:

 
1.
The service is removed from the framework's service registry so that it may no longer be used. ServiceReference s for the service may no longer be used to get a service object for the service.

2.
A ServiceEvent of type ServiceEvent.UNREGISTERING is synchronously sent so that bundles using this service may release their use of the service.

3.
For each bundle whose use count for this service is greater than zero:

4.
The bundle's use count for this service is set to zero.

5.
If the service was registered with a ServiceFactory, the ServiceFactory.ungetService(Bundle, ServiceRegistration, Object) method is called to release the service object for the bundle.

Throws:

javalang.IllegalStateException— If this ServiceRegistration has already been unregistered.

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
18.216.232.11