Registering OSGi services
You can create an object and register it as an OSGi service for use by third-party features.
About this task
By using plain old Java code, you can create an object,
and then register it as a service using the BundleContext
class.
Because the code has to run, you typically register the object in
a BundleActivator
interface. When you register the
object, you can specify what interfaces it provides, and supply a
property map. A ServiceRegistration
object is returned;
if necessary, you can use the ServiceRegistration
object
to change the properties at any time. When the service is completed,
you use the ServiceRegistration
object to unregister
the service.
To obtain a service, you query the BundleContext
for
a service that implements a required interface and, optionally, supply
an LDAP-syntax filter to match the service properties. Depending on
the method you call, you can retrieve the best match or all the matches.
You can then use the returned ServiceReference
that
provides the properties to do further matching in your code. You can
use the ServiceReference
to get the actual service
object. When you have finished using the service, you use the BundleContext
to
release the service.