接口 PrototypeServiceFactory<S>
-
- 类型参数:
S- Type of Service
- 所有超级接口:
ServiceFactory<S>
@ConsumerType public interface PrototypeServiceFactory<S> extends ServiceFactory<S>
A factory forprototype scopeservices. The factory can provide multiple, customized service objects in the OSGi environment.When registering a service, a
PrototypeServiceFactoryobject can be used instead of a service object, so that the bundle developer can create a customized service object for each caller that is using the service.When a caller uses a
ServiceObjectstorequesta service object, the framework calls thegetServicemethod to return a service object customized for the requesting caller. The caller canreleasethe returned service object and the framework will call theungetServicemethod with the service object.When a bundle uses the
BundleContext.getService(ServiceReference)method to obtain a service object, the framework must act as if the service hasbundle scope. That is, the framework will call thegetServicemethod to obtain a bundle-scoped service object which will be cached and have a use count. SeeServiceFactory.A bundle can use both
ServiceObjectsandBundleContext.getService(ServiceReference)to obtain a service object for a service.ServiceObjects.getService()will always return a service object provided by a call togetService(Bundle, ServiceRegistration)andBundleContext.getService(ServiceReference)will always return the bundle-scoped service object.PrototypeServiceFactoryobjects are only used by the Framework and are not made available to other bundles in the OSGi environment. The Framework may concurrently call aPrototypeServiceFactory.- 从以下版本开始:
- 1.8
- 作者:
- $Id: PrototypeServiceFactory.java 1614569 2014-07-30 07:22:32Z cziegeler $
- 另请参阅:
BundleContext.getServiceObjects(ServiceReference),ServiceObjects
-
-
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 SgetService(Bundle bundle, ServiceRegistration<S> registration)Returns a service object for a caller.voidungetService(Bundle bundle, ServiceRegistration<S> registration, S service)Releases a service object customized for a caller.
-
-
-
方法详细资料
-
getService
S getService(Bundle bundle, ServiceRegistration<S> registration)
Returns a service object for a caller.The Framework invokes this method for each caller requesting a service object using
ServiceObjects.getService(). The factory can then return a customized service object for the caller.The Framework must check that the returned service object is valid. If the returned service object is
nullor is not aninstanceofall the classes named when the service was registered, a framework event of typeFrameworkEvent.ERRORis fired containing a service exception of typeServiceException.FACTORY_ERRORandnullis returned to the caller. If this method throws an exception, a framework event of typeFrameworkEvent.ERRORis fired containing a service exception of typeServiceException.FACTORY_EXCEPTIONwith the thrown exception as the cause andnullis returned to the caller.- 指定者:
getService在接口中ServiceFactory<S>- 参数:
bundle- The bundle requesting the service.registration- TheServiceRegistrationobject for the requested service.- 返回:
- A service object that must be an instance of all the classes named when the service was registered.
- 另请参阅:
ServiceObjects.getService()
-
ungetService
void ungetService(Bundle bundle, ServiceRegistration<S> registration, S service)
Releases a service object customized for a caller.The Framework invokes this method when a service has been released by a bundle such as by calling
ServiceObjects.ungetService(Object). The service object may then be destroyed.If this method throws an exception, a framework event of type
FrameworkEvent.ERRORis fired containing a service exception of typeServiceException.FACTORY_EXCEPTIONwith the thrown exception as the cause.- 指定者:
ungetService在接口中ServiceFactory<S>- 参数:
bundle- The bundle releasing the service.registration- TheServiceRegistrationobject for the service being released.service- The service object returned by a previous call to thegetServicemethod.- 另请参阅:
ServiceObjects.ungetService(Object)
-
-