1

eclipse OSGi Service Activator Toolkit 提供了一个框架,可以简化处理 budles 之间的依赖关系。

可以从 org.eclipse.soda.sat.core.framework.BaseBundleActivator 派生并覆盖(例如)activate() 方法来执行一些特定的初始化工作。

签名受保护 void activate(){}

这导致了一个问题:“如果 activate() 失败,我们打算做什么?”,假设由于某种原因我们无法正确初始化。我不能抛出异常,方法签名不允许这样做。

4

2 回答 2

1

如果您使用的是 Equinox(使用 org.eclipse.osgi_3.5.1.R35x_v20090827 测试),则在 activate() 方法中抛出 RuntimeException 或错误对您没有帮助。独立于您抛出捆绑包的内容最终将处于状态 ACTIVE。

我认为这种行为是 Equinox 特有的(错误?),因为据我了解,这违反了 OSGi 规范。

于 2010-06-07T08:34:06.887 回答
0

It's still possible to throw RuntimeException and Error (And Exceptions that inherit these). (Remember that Error indicates serious problems that a reasonable application should not try to catch.)

It would also seems like a good idea to output something to your logging facility.

The alternative you choose is dependent on the situation; what the root cause of the failed activation is. If the cause is something abnormal, that should not happen during normal circumstances, an Error or RuntimeException (and ofcourse loggin) feels right.

于 2009-05-08T20:36:19.263 回答