Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't OSGi Declarative Services (DS) annotations inherited from super classes?

The OSGi Declarative Services (DS) specifications define annotations which can be processed by tools, like Bnd, into the component description xml which is used at runtime. 112.8.1 in the R6 spec says:

The Component Annotations are not inherited, they can only be used on a given class, annotations on its super class hierarchy or interfaces are not taken into account.

Why are they specified to not allow inheritance?

like image 394
BJ Hargrave Avatar asked Jun 07 '16 14:06

BJ Hargrave


1 Answers

The DS annotations provided by the Apache Felix project once had support for DS extensibility. Based on this implementation we tried to standardize this as part of the work specificying the official OSGi DS annotations.

The problem, though, is that we get into nasty coupling issues here between two implementation classes across bundle boundaries and we cannot express this dependency properly using Import-Package or Require-Capability headers.

Some problems springing to mind:

  • Generally you want to make bind and unbind methods private. Would it be ok for DS to call the private bind or unbind method on the base class ? (Technically this can well be done, but would it be conceptually ok ?)
  • What if we have private methods but the implementor decides to change the name of the private methods ? After all they are private and not part of the API surface. The extender will fail as the bind/unbind methods are listed in the descriptors provided by and for the extension class and they still name the old method names.
  • If we don’t support private method names for that we would require these bind/unbind methods to be protected or public. And thus we force implementation-detail methods to become part of the API. Not very nice IMHO.
  • Note: package private methods don’t work as two different bundles should not share the same package with different contents.

We argued back then that it would be ok-ish to have such inheritance within a single bundle but came to the conclusion that this limitation, the explanations around it, etc. would not be worth the effort. So we dropped the feature again from the specification roadmap.

like image 70
fmeschbe Avatar answered Sep 28 '22 11:09

fmeschbe