...
To simplify the tasks of generating the SCR Desriptor and adding the Service-Component
header to the bundle manifest, the Maven SCR Plugin may be used. This helps keeping the descriptor and the code in sync especially during development.
Management
The OSGi Compendium specification defines no management API for Declarative Services. As of version 0.9.0-20071123.131249-8 a simple management API is provided the Apache Felix implementation. The bundle itself also has a Felix Shell Command providing easy commands to introspect the states of the registered components.
Shell Command
The management API is made available to the Felix Shell as the scr
command with a short list of subcommands:
Synopsis | Description |
---|---|
| Show help of the specific |
| List registered components of the bundle specified by |
| Show a complete information dump of the given component. This dump includes the name, status, provided services and information on the service references |
| Enable the given component if not already enabled. If the component is already destroyed or enabled, this command has no effect. |
| Disable the given component if not already disabled. If the component is already destroyed or disabled, this command has no effect. |
API Use
The API consists of the main interface org.apache.felix.scr.ScrService
and two helper interfaces org.apache.felix.scr.Component
describing a registered component and org.apache.felix.scr.Reference
describing a single reference of a registered component. To access the management API, client applications just ask for the ScrService
as usual:
Code Block |
---|
....
ServiceReference scrServiceRef = bundleContext.getServiceReference( ScrService.class.getName() );
ScrService scrService = (ScrService) bundleContext.getService(scrServiceRef);
....
|
Alternatively, you may of course use the ServiceTracker
or if you are using the ScrService
in a component, you may have the ScrService
bound according to the component declaration.
The ScrService
allows access to all registered components, to a specific component by component ID or to all registered components of a specific bundle.
Summary
This tutorial just listed some very basic information on Declarative Service. To get more information, for example on hoe the Configuration Admin Service may be used to configure components, refer to the Declarative Services Sepecification in the OSGi Service Platform Service Compendium book.
...