OSGi provides start level but it's not sufficient to control service configuration and composition.
If you want fine-grained service control, you can use org.osgi.util.tracker.ServiceTracker. Extend ServiceTracker class and override addingService and removedService methods.
OSGi framework saves bundle states and restore states. So BundleActivator started automatically when framework starts. BundleActivator should instanciate and open a ServiceTracker object first, and record all registered service references. (use bundleContext.getAllServiceReferences) ServiceTracker check service requirements for each addingService(). If all requirements are met, tracker can initiate automatic service provisioning.
Example Provisioning Sequence:
- OSGi framework started by OS boot script.
- All OSGi bundles started by OSGi frameworks.
- Automatic provisioning bundle also will be started.
- BundleActivator finds all service references and tracks new service registration.
- Provisioning triggered.
* JPA module configured. (database configuration)
* Web server configured. (port, document root, etc)
* All servlets are registered to web server. (name, url pattern, etc)
- Now all OSGi services configured and composed properly. Service ready.
If you want fine-grained service control, you can use org.osgi.util.tracker.ServiceTracker. Extend ServiceTracker class and override addingService and removedService methods.
OSGi framework saves bundle states and restore states. So BundleActivator started automatically when framework starts. BundleActivator should instanciate and open a ServiceTracker object first, and record all registered service references. (use bundleContext.getAllServiceReferences) ServiceTracker check service requirements for each addingService(). If all requirements are met, tracker can initiate automatic service provisioning.
Example Provisioning Sequence:
- OSGi framework started by OS boot script.
- All OSGi bundles started by OSGi frameworks.
- Automatic provisioning bundle also will be started.
- BundleActivator finds all service references and tracks new service registration.
- Provisioning triggered.
* JPA module configured. (database configuration)
* Web server configured. (port, document root, etc)
* All servlets are registered to web server. (name, url pattern, etc)
- Now all OSGi services configured and composed properly. Service ready.




