5

I try to learn how osgi works. I've written my first hello-world bundle which gives some console output when the start-method of the bundle activator class is executed. Now, I've read about the lazy starting mechanism and I put this flag to my bundle manifest. then, I started the equinox console, installed my bundle and started it. but now I would have expected my bundle to be marked as 'starting'. but instead it already calls it's start method and is marked as active. did I understand anything wrong with the lazy starting mechanism???

2 Answers 2

8

The lazy-start flag is used when you have other bundles that depend on your bundle and classes in your bundle.

Say you have two bundles A and B, where

  • A exports the class C
  • B depends on A
  • B contains a class D that refers C

What happens when the bundle B is activated?

Without the lazy-load flag, the A bundle is loaded and activated first.

With the lazy-load flag, the A bundle is not loaded or activated until the class D needs to refer to the class C.

That can make a very big difference in the activation profile, as the load and activation of bundles are postponed to happen as late as possible with the lazy-load flag so the initial response from the bundle is very fast...

On the contrary, this flag also makes it a hole lot more difficult to reason about the execution time for methods in B as this can be intercepted with load and activation of bundles at any time....

1
  • Thanks a lot to both of you!!! This has not been explained very well in my book but now I understand it :-) Jul 16, 2011 at 19:55
3

You said, you already started your bundle after install - if you start your bundle manually, it is activated regardless of the lazy activation policy.

According to the OSGi specification the following is true for activation:

A lazy activation policy indicates that the bundle, once started, must not be activated until a class is loaded from it; either during normal class loading or via the Bundle loadClass method. Resource loading does not trigger the activation. This change from the default eager activation policy is reflected in the state of the bundle and its events. When a bundle is started using a lazy activation policy, the following steps must be taken:

  • A Bundle Context is created for the bundle.
  • The bundle state is moved to the STARTING state.
  • The LAZY_ACTIVATION event is fired.
  • The system waits for a class load from the bundle to occur.
  • The normal STARTING event is fired.
  • The bundle is activated.
  • The bundle state is moved to ACTIVE.
  • The STARTED event is fired.

If the activation fails because the Bundle Activator start method has thrown an exception, the bundle must be stopped without calling the Bundle Activator stop method. These steps are pictured in a flow chart in Figure 4.29. This flow chart also shows the difference in activation policy of the normal eager activation and the lazy activation.

Update: as I cannot say which version of the specification I have opened at the time I wrote the answer (however, I believe, it was either 4.2 or 4.3), I have checked the current, v5.0 specification, and section 4.4.6.2 contains the actual, semantically equivalent place.

2
  • 1
    You should present the source of the specification. Specification might change with time and future readers (like me) do not know where and from which version you got that quote. Sep 2, 2013 at 10:59
  • 1
    Thanks for the comment; I have added references to the specification. Sep 2, 2013 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.