0

Is there a way to prevent a Bundle from being marked as 'ACTIVE' should one of its DS components fails to initialise?

For example if I were to implement BundleActivator I could throw a BundleException in the start() method and no services offered by that bundle I can prevent from being registered.

Using Declarative Services in my @Activate method I may want to throw an exception if it cannot initialise for whatever reason. I have found though that doing so does not prevent the bundle from being marked as 'ACTIVE'. I also assume that failure of one component does not prevent other components in the bundle from becoming active?

If, for example, I have several components and one fails to initialise I would then like ALL other components to be deactivated and the bundle as a whole to be NOT active i.e. fail-fast.

Is there a way to do this with Declarative Services?

D-Dᴙum
  • 7,689
  • 8
  • 58
  • 97

1 Answers1

0

No this is not possible or desirable. The component lifecycle is separate from the bundle lifecycle. You should not be looking to the bundle state when you want to know about the state of components within it.

Also the lifecycle of each component is independent. You can deliver multiple components within a bundle but that is really just a convenience to allow them to share static (i.e. compile time) dependencies. If you need to tie the lifecycle of one component to another, you should make a service reference between them.

It would help if you would explain why you want a component to fail when another unrelated component happens to fail. Then maybe we can offer a better solution to the underlying problem.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • This question arose after a previous one you had answered: https://stackoverflow.com/questions/47738402/override-require-capability-in-maven-bundle-plugin. I found that it was possible for my PU to fail, because I hadn't started my DB for example, and within that same bundle my DAO was not registered as a service (as desired) but the Bundle was marked as Active. I suppose the issue I was thinking of was more practical. If something isn't working as expected but the bundle status via Karaf commandline reports the bundle as Active yet behind the scenes the components have failed. – D-Dᴙum Dec 20 '17 at 07:47
  • Yes, the mistake is inferring that "bundle active" means "everything in this bundle is completely working", which is an invalid inference. Instead you should be looking at the status of DS components using the console. – Neil Bartlett Dec 20 '17 at 16:57