I want to prevent starting the bundle under certain circumstances (for
example bundle did not authorize itself)

Javadoc of BundleActivator#start
(https://osgi.org/javadoc/r4v43/core/org/osgi/framework/BundleActivator.html)
states:
"If this method throws an exception, this bundle is marked as stopped and
the Framework will remove this bundle's listeners, unregister all services
registered by this bundle, and release all services used by this bundle."

One difference is, that I'm using Declarative Service approach instead of
BundleActivator:
  @Activate
  public void start(final BundleContext ctx, final Map<String, Object>
props) {
    System.out.println("Starting...");
    if(true) {
      throw new RuntimeException("unauthorized");
    }
  }

But I thought it should behave in similar way. Unfortunately when I do:
301 | Resolved |  80 | 0.0.1          | My Bundle
karaf@root()> bundle:start 301
Starting...
Starting...

The bundle:
* Tries to activate TWO times (why?)
* is in WAITING status (instead of RESOLVED)
karaf@root()> bundle:list
301 | Waiting |  80 | 0.0.1          | My Bundle

And the worst thing is that when I invoke start for the second time:
karaf@root()> bundle:start 301
karaf@root()>
* It does not do anything (nothing is printed in the console, it does not
try to authorize for the second time)

Is this the right behavior of Karaf?
If yes, then how can I programmatically prevent starting of the Declarative
Service bundle?

Kind regards,
Kamil



--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html

Reply via email to