`
Jameslyy
  • 浏览: 408100 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Eclipse插件和OSGI束(Plug-ins and bundles)

阅读更多
The mechanics for supporting plug-ins are implemented using the OSGi framework. From this standpoint, a plug-in is the same thing as an OSGi bundle. The bundle and its associated classes specify and implement the process for Java class-loading, prequisite management, and the bundle's life-cycle. For the rest of this discussion, we use the terms plug-in and bundle interchangeably, unless discussing a particular class in the framework.

插件支持结构是通过OSGI框架实现的,从这个角度来看,一个插件等同于一个OSGI束(bundle)。bundle及其相关的类定义和实现了java类的加载、管理和bundle的生命周期。在后面的讨论中,除非是框架中一个特殊的类,“plug-in”和“bundle”交互使用。

Plugin
The Plugin class represents a plug-in that is running in the platform. It is a convenient place to centralize the life-cycle aspects and overall semantics of a plug-in. A plug-in can implement specialized function for the start and stop aspects of its life-cycle. Each life-cycle method includes a reference to a BundleContext which can supply additional information.

Plugin类描述了一个在平台上运行的插件,这样方便集中插件的生命周期和全部语意的管理。一个插件能够实现插件生命周期开始和结束特殊功能。每个生命周期方法包含一个能够提供额外信息的束上下文(BundleContext)参照。

The start portion of the life-cycle is worth particular discussion. We've seen already that information about a plug-in can be obtained from the plug-in's manifest file without ever running any of the plug-in's code. Typically, some user action in the workbench causes a chain of events that requires the starting of a plug-in. From an implementation point of view, a plug-in is never started until a class contained the in the plug-in needs to be loaded.

插件生命周期的启动部分特别值得讨论。我们可以看到包含在插件的manifest文件中的插件信息,而不需要运行插件的任何代码。通常,工作台中的用户行为触发一连串的事件,而引起插件的启动。通过实现的角度来看,除非插件中的一个类需要加载,插件不会运行。

The start method has been a convenient place to implement initialization and registration behavior for a plug-in. However, it is important to realize that your plug-in can be started in many different circumstances. Something as simple as obtaining an icon to decorate an object can cause one of your plug-in's classes to be loaded, thus starting your plug-in. Over-eager initialization can cause your plug-in's code and data to be loaded long before it is necessary. Therefore, it's important to look closely at your plug-in's initialization tasks and consider alternatives to performing initialization at start-up.

插件的启动方法方便于实现插件的初始化和注册行为。但是,插件可以在许多不同的环境中启动,认识到这一点很重要。获得一个用于修饰对象的图标这样简单的动作都可以导致引起插件类的加载,从而到引起插件的启动。过多的初始化导致插件在需要之前就花费很长时间加载插件的代码和数据。因此,认真检查插件的初始化任务并考虑换一种方法在启动时实现初始化,是非常有意义的。

Registration activities such as registering listeners or starting background threads are appropriate during plug-in start-up if they can be performed quickly. However, it is advisable to trigger these actions as part of accessing the plug-in's data if the registration activities have side-effects such as initializing large data structures or performing unrelated operations.


在插件启动时,如果运行速度很快,可以进行各种注册,例如注册监听器或者启动后台线程。但是,如果注册行为具有副作用,例如初始化大量数据结构或者执行不相关的操作,在访问插件数据时触发注册行为才是更为可取的。

Initialization of data is best done lazily, when the data is first accessed, rather than automatically in the start-up code. This ensures that large data structures are not built until they are truly necessary.

数据的初始化最好是懒加载,在数据第一次使用时加载,而不是在启动代码中加载。这样保证了除非在真正必要的时候大型数据结构不会构建。

Bundle Context
Life-cycle management is where the OSGi "bundle" terminology and the platform's "plug-in" terminology meet. When your plug-in is started, it is given a reference to a BundleContext from which it can obtain information related to the plug-in. The BundleContext can also be used to find out about other bundles/plug-ins in the system.

生命周期管理是术语OSGI “bundle”和平台“plugin”相通的地方。当插件启动时,获得一个BundleContext的参照,通过这个参照可以获得插件相关的信息。BundleContext也可以用于获得系统中其他束/插件。

BundleContext.getBundles() can be used to obtain an array of all bundles in the system. Listeners for BundleEvent can be registered so that your plug-in is aware when another bundle has a change in its life-cycle status. See the javadoc for BundleContext and BundleEvent for more information.

BundleContext.getBundles()可以用于获得系统所有bundle的一个数组。可以注册BundleEvent的监听器(Listeners),从而在另一个bundle在其生命周期状态中发生变化时,你的插件能够得到消息。更多的内容可以查看BundleContext 和 BundleEvent的文档。


Prior to 3.0, a plug-in registry (IPluginRegistry) was provided to supply similar information. For example, it could be queried for the plug-in descriptors of all plug-ins in the system. This registry is now deprecated and BundleContext should be used for this purpose. The platform registry is now used exclusively for information about extensions and extension points.

相对于3.0,插件的注册器(IPluginRegistry)提供类似的信息。例如,可以在系统中查询所有插件的插件描述。这个注册器现在已经撇弃,而使用BundleContext来实现。现在平台上的注册器专门用于注册扩展和扩展点的相关信息。


Bundle Activator
The BundleActivator interface defines the start and stop behavior implemented in Plugin. Although the Plugin class is a convenient place to implement this function, a plug-in developer has complete freedom to implement the interface for BundleActivator in any class appropriate for the plug-in's design. In fact, your plug-in need not implement this interface at all if it does not have specific life-cycle management needs.

BundleActivator接口定义了插件启动和停止运行的行为。尽管这个插件类方便于实现这个功能,插件开发者在任何合适的类中完全可以灵活地实现这个接口。实际上如果插件没有特殊的生命周期的管理的需要的话,插件根本不需要实现这个接口。

Bundles
Underneath every plug-in lies an OSGi bundle managed by the framework. The Bundle is the OSGi unit of modularity. Fundamentally, a bundle is just a collection of files (resources and code) installed in the platform. Each bundle has its own Java class loader, and includes protocol for starting, stopping, and uninstalling itself. From the Eclipse platform point of view, Bundle is merely an implementation class. Plug-in developers do not extend the bundle class, but use Plugin or other BundleActivator implementations to represent the plug-in.

在每一个插件后面都有一个框架的OSGI bundle。Bundle时OSGI模块性单元。从根本上说,一个bundle是一个安装在平台中的文件(资源和代码)的集合。每一个bundle有自己的Java类加载器,并且包括启动、停止和卸载的协议。从Eclipse平台角度来看,Bundle仅仅是一个实现类。插件开发者没有扩展bundle类,但是使用Plugin或者其他BundleActivator实现去描述插件。

2007.06.27(translaition)
分享到:
评论

相关推荐

    Eclipse.Plug-ins.Third Edition(PDF)

    《Eclipse Plug-ins 第三...通过阅读《Eclipse Plug-ins 第三版》,开发者不仅可以学会如何编写Eclipse插件,还能对整个Eclipse生态系统有更深入的理解,从而能够充分利用Eclipse的强大功能,提升开发效率和应用质量。

    Eclipse.Plug-ins.Third+Edition(英文版)

    《Eclipse Plug-ins Third Edition》是由Eric Clayberg和Dan Rubel合著的一本关于Eclipse插件开发的专业书籍。本书详细介绍了如何利用Eclipse Platform Development Environment (PDE)工具来设计、开发、测试和部署...

    osgi-resource-locator-1.0.1-API文档-中文版.zip

    赠送jar包:osgi-resource-locator-1.0.1.jar; 赠送原API文档:osgi-resource-locator-1.0.1-javadoc.jar; 赠送源代码:osgi-resource-locator-1.0.1-sources.jar; 赠送Maven依赖信息文件:osgi-resource-locator...

    Eclipse Plug-ins Third Edition.rar

    《Eclipse插件开发第三版》是一本深入探讨Eclipse平台扩展开发的专著,针对Eclipse插件的创建、调试和发布提供了详尽的指导。这本书的核心内容围绕着如何利用Eclipse RCP(Rich Client Platform)来构建可复用、可...

    osgi-resource-locator-1.0.1-API文档-中英对照版.zip

    赠送jar包:osgi-resource-locator-1.0.1.jar; 赠送原API文档:osgi-resource-locator-1.0.1-javadoc.jar; 赠送源代码:osgi-resource-locator-1.0.1-sources.jar; 赠送Maven依赖信息文件:osgi-resource-locator...

    killbill-osgi-bundles-lib-slf4j-osgi-0.8.4.zip

    总的来说,"killbill-osgi-bundles-lib-slf4j-osgi-0.8.4.zip" 和 "java-goinstant-auth.zip" 分别涉及了OSGi模块化、日志抽象和实时协作领域的技术,都是Java开发中的重要工具,尤其适用于构建复杂、模块化且需要...

    Addison.Wesley.Eclipse.Plug-ins.Third Edition.Dec.2008

    通过阅读《Addison.Wesley.Eclipse.Plug-ins Third Edition》,开发者不仅可以学习到Eclipse插件开发的技能,还能深入理解Eclipse平台的工作原理,从而更好地利用这个强大的工具链来提升开发效率和软件质量。

    Eclipse.Plug-ins.3rd.2008

    《Eclipse Plug-ins 3rd 2008》会介绍如何利用OSGi和Eclipse SDK创建自定义的开发工具。 书中可能涵盖了以下关键知识点: 1. **Eclipse插件架构**:讲解Eclipse的插件模型,包括插件的生命周期、API接口、插件间的...

    killbill-osgi-bundles-test-payment-0.6.1.zip

    【标题】:“killbill-osgi-bundles-test-payment-0.6.1.zip”是一个开源项目的压缩包,其中包含了KillBill OSGi Bundle测试支付模块的0.6.1版本。 【描述】:“lint-maven-plugin.zip”是Maven的一个插件,它的...

    Addison.Wesley.Eclipse.Plug-ins.Third Edition.Dec.2008.pdf

    总的来说,《Addison.Wesley.Eclipse.Plug-ins.Third Edition.Dec.2008》是学习和掌握Eclipse插件开发的宝贵资源,无论你是初学者还是经验丰富的开发者,都能从中获得丰富的知识和技巧,提升你在Eclipse平台上的开发...

    spring-osgi-1.2.1-with-dependencies.zip

    spring-osgi-1.2.1-with-dependencies.zip spring-osgi-1.2.1-with-dependencies.zip spring-osgi-1.2.1-with-dependencies.zip

    spring-osgi-1.2.0-rc1-with-dependencies.zip

    "spring-osgi-1.2.0-rc1"是Spring OSGi的一个早期版本,"RC1"代表Release Candidate 1,意味着这是正式发布前的最后一个测试版本。在这个版本中,开发者可以期待一些新特性和改进,但同时也可能存在一些未发现的...

    RCP+Plug-in开发自学教程_RCP+Plug-in开发自学教程_源码

    1. **OSGi服务**:Eclipse RCP基于OSGi框架,提供动态服务发现和依赖管理,有助于保持系统的灵活性和稳定性。 2. **国际化**:支持多语言,通过资源包(.properties文件)实现文本的本地化。 3. **自定义启动器**:...

    OSGI 实例eclipse插件开发

    OSGI(Open Services Gateway Initiative)是一种模块化系统和Java服务框架,它允许...同时,掌握OSGI的生命周期管理和服务发现机制,以及Spring在OSGI环境下的工作原理,对于构建灵活、可扩展的Eclipse插件至关重要。

    eclipse_plug_ins_third_edition.pdf

    书中会深入讲解Eclipse插件的生命周期、依赖关系以及如何设计和实现插件的各个部分,包括插件manifest文件、插件元数据和插件激活类。 2. **开发环境配置**:了解如何设置Eclipse开发环境,安装必要的插件如PDE...

    org.osgi.core-4.2.0

    OSGi 是一个 Java 平台的模块化系统和服务平台,它提供了一种标准的方式来组织和管理 Java 应用程序的组件和服务。 描述 "osgi最新jar包org.osgi.core-4.2.0" 告诉我们这是一个最新的 OSGi jar 包,其中包含了 OSGi...

Global site tag (gtag.js) - Google Analytics