延迟激活Eclipse插件 [英] Lazy activation of Eclipse plugins

查看:131
本文介绍了延迟激活Eclipse插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么是Eclipse清单编辑器中的在加载其类之一时激活此插件"复选框.

I would like to know what is "Activate this plug-in when one of its classes is loaded" check-box in Eclipse manifest editor useful for.

我认为Eclipse始终使用惰性初始化"方法.这个选项与插件的BundleActivator类有关系吗?初始化和激活有什么不同吗?

I thought Eclipse always use "lazy initialization" approach. Does have this option a relation to the BundleActivator class of the plugin? is initialization something different to activation?

此处是类似的问题,但我没有完全理解它.

Here is a similar question, but I don't understand it entirely.

推荐答案

勾选该框会在清单中设置以下标头:

Ticking the box causes the following header to be set in the manifest:

Bundle-ActivationPolicy: lazy

我将从纯" OSGi的处理方式开始.如果使用START_ACTIVATION_POLICY标志启动捆绑包,则捆绑包进入STARTING状态,但不会调用激活程序的start()方法,并且不会为捆绑包分配ClassLoader.捆绑软件将一直处于STARTING状态,直到由于某种原因需要从捆绑软件中加载类为止.此时,将分配一个ClassLoader,并实例化激活器(如果有的话),并在加载请求的类之前调用​​其start()方法.

I'll start with how "pure" OSGi deals with this. IF the bundle is started with the START_ACTIVATION_POLICY flag then the bundle enters the STARTING state but the activator's start() method is not invoked and a ClassLoader is not allocated for the bundle. The bundle stays in STARTING until, for whatever reason, a class needs to be loaded from the bundle. At that point a ClassLoader is allocated and the activator (if any) is instantiated and its start() method is invoked before the requested class is loaded.

但是Eclipse在顶部附加了其他语义.作为背景,Eclipse始终尝试避免启动捆绑软件,以使启动时间最小化.默认情况下会启动一组非常小的核心捆绑包(列表位于configuration/config.ini中),其中一个捆绑包称为p2"simpleconfigurator". simpleconfigurator查找具有Bundle-ActivationPolicy:lazy标头的包,并使用START_ACTIVATION_POLICY标志启动它们……因此,这些包将如上所述被懒惰"地启动.

However Eclipse layers additional semantics on the top. As background, Eclipse always tries to avoid starting bundles in order to keep its start-up time minimal. A very small core set of bundles is started by default (the list is in configuration/config.ini) and one of these is called the p2 "simpleconfigurator". The simpleconfigurator looks for bundles that have the Bundle-ActivationPolicy:lazy header and it starts them with the START_ACTIVATION_POLICY flag... therefore these bundles will be "lazily" started as described above.

重要的一点是,不包含标头所有个其他捆绑包将根本不会在Eclipse下启动.它们将保持为RESOLVED状态,不会调用其激活器,并且如果它们包含任何声明性服务组件,则将不会加载它们.这是因为声明式服务仅查看处于活动或开始状态的捆绑软件.

The important point is that all other bundles that do not contain the header will not be started at all under Eclipse. They will stay in RESOLVED state, their activators will not be invoked, and if they contain any Declarative Services component they will not be loaded. This is because Declarative Services only ever looks at bundles that are in ACTIVE or STARTING state.

因此,使用标头的主要原因是,如果我们要编写一个包含需要在Eclipse下工作的Declarative Services组件的捆绑软件.

在其他环境中,无需使用标头.大多数普通的OSGi应用程序只是启动所有捆绑软件,而不是尝试有选择地启动捆绑软件的子集.请注意,这并不意味着OSGi应用程序不必担心延迟加载!声明式服务已经支持延迟加载,而不会弄乱包类加载触发器.在我看来,Eclipse犯了这个错误,并为捆绑软件的生命周期增加了不必要的复杂性.但是,如果您在Eclipse中运行,则别无选择,只能了解并克服其局限性.

In other environments there is no need to use the header. Most normal OSGi apps simply start all bundles, rather than trying to selectively start a subset of bundles. Note that this doesn't mean OSGi apps don't worry about lazy loading! Declarative Services already supports lazy loading without messing around with bundle class loading triggers. In my opinion Eclipse gets this wrong and has added unnecessary complexity to the bundle lifecycle. Nevertheless if you are running in Eclipse then you have no choice but to understand and work with its limitation.

这篇关于延迟激活Eclipse插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆