osgi包生命周期问题

发布于 2024-11-24 12:06:13 字数 205 浏览 1 评论 0原文

我尝试了解 osgi 是如何工作的。我已经编写了第一个 hello-world 包,当执行包激活器类的启动方法时,它会提供一些控制台输出。现在,我已经了解了延迟启动机制,并将此标志放入我的捆绑清单中。然后,我启动了 Equinox 控制台,安装了我的包并启动了它。但现在我希望我的包被标记为“开始”。但它已经调用了它的 start 方法并被标记为活动状态。 我是否理解延迟启动机制有什么问题???

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謌踐踏愛綪 2024-12-01 12:06:13

当您有依赖于您的捆绑包和捆绑包中的类的其他捆绑包时,将使用惰性启动标志。

假设您有两个包 A 和 B,其中

  • A 导出类 C
  • B 依赖于 A
  • B 包含引用 C 的类 D

激活包 B 时会发生什么?

如果没有延迟加载标志,则首先加载并激活 A 包。

使用延迟加载标志,直到类 D 需要引用类 C 时,A 捆绑包才会被加载或激活。

这可以在激活配置文件中产生很大的差异,因为加载和激活使用延迟加载标志,捆绑包的激活会被推迟到尽可能晚的时间,因此捆绑包的初始响应非常快...

相反,这个标志也使得推断执行时间变得更加困难对于 B 中的方法,因为这可以通过加载和激活包来拦截任何时候....

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

一曲琵琶半遮面シ 2024-12-01 12:06:13

您说过,您在安装后已经启动了捆绑包 - 如果您手动启动捆绑包,则无论延迟激活策略如何,它都会被激活。

根据 OSGi 规范,以下激活正确:

惰性激活策略表明捆绑包一旦启动,必须
在从中加载类之前不会被激活;要么在正常期间
类加载或通过 Bundle loadClass 方法加载。资源加载
不触发激活。此更改来自默认的 eager
激活策略反映在捆绑包及其状态中
事件。当使用惰性激活策略启动捆绑包时,
必须采取以下步骤:

  • 为该包创建了一个包上下文。
  • 捆绑包状态已转至 STARTING 状态。
  • LAZY_ACTIVATION 事件已触发。
  • 系统等待从包中加载类。
  • 触发正常的 STARTING 事件。
  • 该捆绑包已激活。
  • 捆绑包状态已转为“ACTIVE”。
  • 已触发 STARTED 事件。

如果激活失败是因为Bundle Activator启动方法有
抛出异常,必须停止捆绑包而不调用
Bundle Activator 停止方法。这些步骤如流程图所示
如图 4.29 所示。该流程图还显示了差异
正常的eager激活和lazy激活策略
激活。

更新:由于我无法说出在写答案时我打开了哪个版本的规范(但是,我相信它是 4.2 或 4.3),所以我检查了当前的 v5.1 版本。 0 规范,第 4.4.6.2 节包含实际的、语义上等效的位置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文