Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

osgi bundle lifecycle question

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???

like image 448
Antje Janosch Avatar asked Jul 16 '11 06:07

Antje Janosch


2 Answers

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....

like image 138
Tonny Madsen Avatar answered Oct 10 '22 04:10

Tonny Madsen


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.

like image 32
Zoltán Ujhelyi Avatar answered Oct 10 '22 03:10

Zoltán Ujhelyi