Java Reference
In-Depth Information
When everything's ready, you can publish your service by using the bundle context:
ServiceRegistration registration =
bundleContext.registerService(interfaces, new LSE(), metadata);
The registry returns a service registration object for the published service, which you
can use to update the service metadata or to remove the service from the registry.
NOTE Service registrations are private. They shouldn't be shared with other
bundles, because they're tied to the lifecycle of the publishing bundle.
The LSE implementation is a POJO . It doesn't need to extend or implement any spe-
cific OSG i types or use any annotations; it just has to match the provided service
details. There's no leakage of OSG i types into service implementations. You don't even
have to use interfaces if you don't want to— OSG i will accept services registered under
concrete class names, but this isn't recommended.
UPDATING SERVICE METADATA
After you've published a service, you can change its metadata at any time by using its
service registration:
registration.setProperties(newMetadata);
This makes it easy for your service to adapt to circumstances and inform consumers
about any such changes by updating its metadata. The only pieces of metadata that
you can't change are service.id and objectClass , which are maintained by the
framework. Other properties that have special meaning to the OSG i framework are
shown in table 4.2.
Table 4.2
Standard OSGi service properties
Key
Type
Description
String[] Class name the service was registered under. You can't
change it after registration.
objectClass
Unique registration sequence number, assigned by the
framework when registering the service. You can't choose
or change it.
service.id
Long
Persistent (unique) service identifier, chosen by you.
service.pid
String
service.ranking
Integer
Ranking used when discovering services. Defaults to 0.
Services are sorted by their ranking (highest first) and then
by their ID (lowest first). Chosen by you.
service.description String
Description of the service, chosen by you.
Name of the vendor providing the service, chosen by you.
service.vendor
String
REMOVING A SERVICE
The publishing bundle can also remove a published service at any time:
registration.unregister();
 
Search WWH ::




Custom Search