Interface ServiceRegistration<S>
-
- Type Parameters:
S- Type of Service.
@ProviderType public interface ServiceRegistration<S>
A registered service.The Framework returns a
ServiceRegistrationobject when aBundleContext.registerServicemethod invocation is successful. TheServiceRegistrationobject is for the private use of the registering bundle and should not be shared with other bundles.The
ServiceRegistrationobject may be used to update the properties of the service or to unregister the service.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ServiceReference<S>getReference()Returns aServiceReferenceobject for a service being registered.voidsetProperties(java.util.Dictionary<java.lang.String,?> properties)Updates the properties associated with a service.voidunregister()Unregisters a service.
-
-
-
Method Detail
-
getReference
ServiceReference<S> getReference()
Returns aServiceReferenceobject for a service being registered.The
ServiceReferenceobject may be shared with other bundles.- Returns:
ServiceReferenceobject.- Throws:
java.lang.IllegalStateException- If thisServiceRegistrationobject has already been unregistered.
-
setProperties
void setProperties(java.util.Dictionary<java.lang.String,?> properties)
Updates the properties associated with a service.The
Constants.OBJECTCLASS,Constants.SERVICE_BUNDLEID,Constants.SERVICE_IDandConstants.SERVICE_SCOPEkeys cannot be modified by this method. These values are set by the Framework when the service is registered in the OSGi environment.The following steps are required to modify service properties:
- The service's properties are replaced with the provided properties.
- A service event of type
ServiceEvent.MODIFIEDis fired.
- Parameters:
properties- The properties for this service. SeeConstantsfor a list of standard service property keys. 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:
java.lang.IllegalStateException- If thisServiceRegistrationobject has already been unregistered.java.lang.IllegalArgumentException- Ifpropertiescontains case variants of the same key name.
-
unregister
void unregister()
Unregisters a service. Remove aServiceRegistrationobject from the Framework service registry. AllServiceReferenceobjects associated with thisServiceRegistrationobject can no longer be used to interact with the service once unregistration is complete.The following steps are required to unregister a service:
- The service is removed from the Framework service registry so that it can no longer be obtained.
- A service event of type
ServiceEvent.UNREGISTERINGis fired so that bundles using this service can release their use of the service. Once delivery of the service event is complete, theServiceReferenceobjects for the service may no longer be used to get a service object for the service. - For each bundle whose use count for this service is greater than
zero:
- The bundle's use count for this service is set to zero.
- If the service was registered with a
ServiceFactoryobject, theServiceFactory.ungetServicemethod is called to release the service object for the bundle.
- Throws:
java.lang.IllegalStateException- If thisServiceRegistrationobject has already been unregistered.- See Also:
BundleContext.ungetService(ServiceReference),ServiceFactory.ungetService(Bundle, ServiceRegistration, Object)
-
-