In OSGi the presentation layer could be a servlet registered in the
Http Service, The Item Service could be an OSGi service that encapsulates the logic and the DataStore could also be an OSGi service that can be used for interacting with the database.
As shown in the diagram above, the web application depends on the item service and the item service depends on the datastore.
What happens if the datastore is not configured or available?
Proxying:
With the proxying approach the Item Service will get injected a proxy to the Data Store, that will block if the Data Store is not available. The Item Service will be registered to the Service Registry and the Web Application will try to use it, even if there is no Data Store. Requests to the Web Application may end up blocked waiting for the Data Store
(which is not ideal).
Cascading:
With the cascading approach the Item Service will only be registered when a Data Store is present. In the same manner the Web Application will only be available if the Item Service is available. So we have a guarantee, that the Web Application will be available if all dependencies in the hierarchy are satisfied. Requests made while there are unsatisfied dependencies will result in an HTTP 404 error which gives a "fail fast" behaviour. Note that whenever the Data Store becomes available both the Item Service and Web Application will automatically detect the change and also become available themselves.
Final Thoughts
Declarative Services is a great tool for managing the dependencies of your components. The cascading approach can be a valuable tool for building robust dynamic, modular applications.
Blueprint is really easy to use and will feel natural to users familiar with spring. Also the proxying behaviour in some cases can be also useful.
So when to use one or the other?
I tend to think that Blueprint shines in cases, where you are constructing components that either have no service dependencies or are not exposed themselves as services. An other case is when "waiting for the service" is more natural. Such examples can be:
- shell commands (usually the are not used as services by other components)
- camel routes (waiting for dependencies is desired)
In cases where there are long dependency chains, components are highly dynamic etc I think that declarative services is a better choice.
Regardless of your choice, you need to know the strengths and weaknesses of your tools!
I hope that this was helpful !!!