|
OSGi™ Service Platform Release 4 Version 4.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Allows services to provide customized service objects in the OSGi environment.
When registering a service, a ServiceFactory
object can be
used instead of a service object, so that the bundle developer can gain
control of the specific service object granted to a bundle that is using the
service.
When this happens, the
BundleContext.getService(ServiceReference)
method calls the
ServiceFactory.getService
method to create a service object
specifically for the requesting bundle. The service object returned by the
ServiceFactory
is cached by the Framework until the bundle
releases its use of the service.
When the bundle's use count for the service equals zero (including the bundle
stopping or the service being unregistered), the
ServiceFactory.ungetService
method is called.
ServiceFactory
objects are only used by the Framework and are
not made available to other bundles in the OSGi environment. The Framework
may concurrently call a ServiceFactory
.
BundleContext.getService(org.osgi.framework.ServiceReference)
Method Summary | |
java.lang.Object |
getService(Bundle bundle,
ServiceRegistration registration)
Creates a new service object. |
void |
ungetService(Bundle bundle,
ServiceRegistration registration,
java.lang.Object service)
Releases a service object. |
Method Detail |
public java.lang.Object getService(Bundle bundle, ServiceRegistration registration)
The Framework invokes this method the first time the specified
bundle
requests a service object using the
BundleContext.getService(ServiceReference)
method. The
service factory can then 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
from the same bundle.
The Framework will check if the returned service object is an instance of
all the classes named when the service was registered. If not, then
null
is returned to the bundle.
bundle
- The bundle using the service.registration
- The ServiceRegistration
object for the
service.
BundleContext.getService(org.osgi.framework.ServiceReference)
public void ungetService(Bundle bundle, ServiceRegistration registration, java.lang.Object service)
The Framework invokes this method when a service has been released by a bundle. The service object may then be destroyed.
bundle
- The bundle releasing the service.registration
- The ServiceRegistration
object for the
service.service
- The service object returned by a previous call to the
ServiceFactory.getService
method.BundleContext.ungetService(org.osgi.framework.ServiceReference)
|
OSGi™ Service Platform Release 4 Version 4.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |