Search code examples
javainheritanceosgideclarative-services

Trying to create an abstract bundle in OSGI


I'd like to create something as an abstract bundle in OSGI. The idea is that when let's say bundle Ax (x going from 1 to 9) needs to bind to bundle B through a service provided by B, this could be done more easily by making asbtractA (so Ax extends abstractA)

Here abstractA is a bundle with a declerative service file. The xml file describes the referenced service to bundle B and in the appropriate class of abstractA the bind unbind and start method are implemented.

Let's assume that Ax has a start method of it's own, startx, and binds to a couple of services, so the bundle has his own .xml file.

Question: Will both start (from abstractBundle) and startx be called? Will the binds from the referenced services of both bundleAx and bundleabstractA take place?


Solution

  • Although of course your specific details are unclear to me, I question the use of 'inheritance' here. It seems to me you may be better off using either:

    1. Delegation. Meaning: delegate the common functionality to a service in bundle A.
    2. A service factory solution. Meaning: create multiple services via a factory pattern where the factory is registered by bundle A.