Spyral
Spyral

Reputation: 772

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?

Upvotes: 1

Views: 218

Answers (2)

Arie van Wijngaarden
Arie van Wijngaarden

Reputation: 1146

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.

Upvotes: 1

Christian Schneider
Christian Schneider

Reputation: 19606

There is no way to create an abstract bundle in OSGi. What you can do though is of course use an abstract class to share some functionality between the bundles.

Btw. if the only thing you want to achieve is to share the DS xml file then you should take a look at the annotation based config for DS. This eliminates the need to write xml completely (it can be generated by a maven plugin from you annotations).

Upvotes: 1

Related Questions