接口 ServiceObjects<S>
-
- 类型参数:
S- Type of Service
@ProviderType public interface ServiceObjects<S>Allows multiple service objects for a service to be obtained.For services with
prototypescope, multiple service objects for the service can be obtained. For services withsingletonorbundlescope, only one, use-counted service object is available to a requesting bundle.Any unreleased service objects obtained from this
ServiceObjectsobject are automatically released by the framework when the bundle associated with the BundleContext used to create thisServiceObjectsobject is stopped.- 从以下版本开始:
- 1.8
- 作者:
- $Id: ServiceObjects.java 1614569 2014-07-30 07:22:32Z cziegeler $
- 另请参阅:
BundleContext.getServiceObjects(ServiceReference),PrototypeServiceFactory
-
-
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 SgetService()Returns a service object for theassociatedservice.ServiceReference<S>getServiceReference()Returns theServiceReferencefor the service associated with thisServiceObjectsobject.voidungetService(S service)Releases a service object for theassociatedservice.
-
-
-
方法详细资料
-
getService
S getService()
Returns a service object for theassociatedservice.This
ServiceObjectsobject can be used to obtain multiple service objects for the associated service if the service hasprototypescope.If the associated service has
singletonorbundlescope, this method behaves the same as calling theBundleContext.getService(ServiceReference)method for the associated service. That is, only one, use-counted service object is available from thisServiceObjectsobject.This method will always return
nullwhen the associated service has been unregistered.For a prototype scope service, the following steps are required to obtain a service object:
- If the associated service has been unregistered,
nullis returned. - The
PrototypeServiceFactory.getService(Bundle, ServiceRegistration)method is called to supply a customized service object for the caller. - If the service object returned by the
PrototypeServiceFactoryobject isnull, not aninstanceofall the classes named when the service was registered or thePrototypeServiceFactoryobject throws an exception,nullis returned and a Framework event of typeFrameworkEvent.ERRORcontaining aServiceExceptiondescribing the error is fired. - The customized service object is returned.
- 返回:
- A service object for the associated service or
nullif the service is not registered, the customized service object returned by aServiceFactorydoes not implement the classes under which it was registered or theServiceFactorythrew an exception. - 抛出:
java.lang.IllegalStateException- If the BundleContext used to create thisServiceObjectsobject is no longer valid.- 另请参阅:
ungetService(Object)
- If the associated service has been unregistered,
-
ungetService
void ungetService(S service)
Releases a service object for theassociatedservice.This
ServiceObjectsobject can be used to obtain multiple service objects for the associated service if the service hasprototypescope. If the associated service hassingletonorbundlescope, this method behaves the same as calling theBundleContext.ungetService(ServiceReference)method for the associated service. That is, only one, use-counted service object is available from thisServiceObjectsobject.For a prototype scope service, the following steps are required to release a service object:
- If the associated service has been unregistered, this method returns without doing anything.
- The
PrototypeServiceFactory.ungetService(Bundle, ServiceRegistration, Object)method is called to release the specified service object.
The specified service object must no longer be used and all references to it should be destroyed after calling this method.
- 参数:
service- A service object previously provided by thisServiceObjectsobject.- 抛出:
java.lang.IllegalStateException- If the BundleContext used to create thisServiceObjectsobject is no longer valid.java.lang.IllegalArgumentException- If the specified service object was not provided by thisServiceObjectsobject.- 另请参阅:
getService()
-
getServiceReference
ServiceReference<S> getServiceReference()
Returns theServiceReferencefor the service associated with thisServiceObjectsobject.- 返回:
- The
ServiceReferencefor the service associated with thisServiceObjectsobject.
-
-