有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    “当前”方法(pre3.5M5,与eclipse3.4类似)的问题在于,Eclipse插件扩展或OSGI DS(声明性服务)都需要一些特定于扩展或OSGI的API出现在插件中

    我鼓励您在这个Powerpoint演示文稿中查看这篇关于声明性服务的精彩介绍:
    Component Oriented Development in OSGi with Declarative Services, Spring Dynamic Modules and Apache iPOJO,来自2009年的日食

    这里有一种味道:


    模块层允许最小化静态依赖关系,更少的静态依赖关系意味着组件工作所需的东西
    服务允许您的组件与其他组件交互

    组件应该实现为POJO(普通的旧Java对象)与OSGi服务粘合在一起

    声明性服务(DS)是OSGi概要第112节中的一个规范
    它是在4.0版中引入的,基于扩展器模型

    与所有扩展器一样,DS代表其他捆绑包执行任务。 DS规范定义了这个扩展器,它由框架实现
    扩展包本身被称为服务组件运行时或SCR

    术语DS和SCR有时会混淆:
    DS是规范,SCR是实现规范的实际捆绑包

    OSGi R4中的DS有显著的改进。2.
    Equinox 3.5M5+支持其中许多更改

    SCR(实现新的和改进的OSGi R4.2 DS-声明性服务-规范的“服务组件运行时”是一个“扩展包”)将:

    • 创建组件
    • 将它们绑定到服务和配置
    • 管理组件的生命周期,以响应绑定服务的进出
    • (可选)将组件本身发布为服务

    你还有舱单。MF:

    Bundle-SymbolicName : mybundle
    Bundle-Version : 1.0.0
    Service-Component : OSGI-INF/minimal. xml
    

    您将使用:

    org.eclipse.equinox.ds <version>.jar
    org.eclipse.equinox.util <version>.jar
    

    SCR将自动找到激活/停用方法
    我们可以通过向XML声明添加属性来将它们称为其他名称

    在R4之前。2.方法名无法更改,必须从DS API中获取类型为ComponentContext的参数。这破坏了组件的性能

    因此,不要编写“BundleActivator”(组件中OSGI特定的API:BAD),而是编写一个普通的POJO对象:

    public class PollingComponent {
        private static final int DEFAULT_PERIOD = 2000;
        private PollingThread thread ;
        protected void activate ( Map<String , Object> config ) {
            System.out.println( " Polling Component Activated " );
            Integer period = (Integer)config.get( " period " );
            thread = new PollingThread(
                period!=null ? period : DEFAULT_PERIOD);
            thread.start();
        }
        protected void deactivate() {
            System.out.println( " Polling Component Deactivated " );
            thread.interrupt();
        }
    }
    

    您将简单地声明您对其他服务的引用:

    <reference name="LOG"
        interface="org.osgi.service.log.LogService "
        bind="setLog" unbind="unsetLog"
        cardinality="0..1"/>
    

    您可以将组件作为服务本身发布:
    这是通过XML描述符中的<service>元素完成的

    <service>
        <provide interface="net ... ContactRepository"/>
        <property name="foo" value="bar"
    </service>
    

    只需添加额外的<provide>元素即可提供多种服务
    使用<property>元素指定服务属性。这些属性被传递到激活中的组件,并发布到服务注册表

  2. # 2 楼答案

    关于日食有一个很好的比较(我想是从2007年开始的:A Comparison of Eclipse Extensions and OSGi Services

    我会遵循你目标平台的惯例。因此,如果你正在为Eclipse3.4编写一个插件,比如说,创建一个Eclipse3.4插件(它将使用MANIFEST.MF作为依赖项,使用plugin.xml作为扩展/扩展点——你链接到的文章是针对Eclipse2.x的)。您可以检查插件目录的内容来确认这一点