|
OSGi™ Core Release 5 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
S
- Type of Servicepublic interface ServiceFactory<S>
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 is decremented to 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(ServiceReference)
Method Summary | |
---|---|
S |
getService(Bundle bundle,
ServiceRegistration<S> registration)
Creates a new service object. |
void |
ungetService(Bundle bundle,
ServiceRegistration<S> registration,
S service)
Releases a service object. |
Method Detail |
---|
S getService(Bundle bundle, ServiceRegistration<S> 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 must check that the returned service object is valid. If
the returned service object is null
or is not an
instanceof
all the classes named when the service was registered,
a framework event of type FrameworkEvent.ERROR
is fired
containing a service exception of type
ServiceException.FACTORY_ERROR
and null
is returned to
the bundle. If this method throws an exception, a framework event of type
FrameworkEvent.ERROR
is fired containing a service exception of
type ServiceException.FACTORY_EXCEPTION
with the thrown exception
as the cause and null
is returned to the bundle. If this method
is recursively called for the specified bundle, a framework event of type
FrameworkEvent.ERROR
is fired containing a service exception of
type ServiceException.FACTORY_RECURSION
and null
is
returned to the bundle.
The Framework caches the valid service object and will return the same
service object on any future call to BundleContext.getService
for
the specified bundle. This means the Framework must not allow this method
to be concurrently called for the specified bundle.
bundle
- The bundle requesting the service.registration
- The ServiceRegistration
object for the
requested service.
BundleContext.getService(ServiceReference)
void ungetService(Bundle bundle, ServiceRegistration<S> registration, S service)
The Framework invokes this method when a service has been released by a bundle. The service object may then be destroyed.
If this method throws an exception, a framework event of type
FrameworkEvent.ERROR
is fired containing a service exception of
type ServiceException.FACTORY_EXCEPTION
with the thrown exception
as the cause.
bundle
- The bundle releasing the service.registration
- The ServiceRegistration
object for the
service being released.service
- The service object returned by a previous call to the
getService
method.BundleContext.ungetService(ServiceReference)
|
OSGi™ Core Release 5 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |