开发者

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 un开发者_JS百科derstand anything wrong with the lazy starting mechanism???


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜