【问题标题】:update dynamically targeting provider in iPOJO更新 iPOJO 中的动态定位提供程序
【发布时间】:2014-11-06 10:05:12
【问题描述】:

我有一个组件声明为:

<ipojo>
    <component classname="HelloClass" name="helloCom" immediate="true">
        <requires field="delayService" id="id1">
        </requires>
    </component>
    <instance component="helloCom" name="hello">
        <property name="requires.from">
            <property name="id1" value="A"/>
        </property>
    </instance> 
</ipojo>

该组件的jar文件:helloComponent.jar

现在,我想将 (value="A") 更新为 (value="AA")。因此,我使用 ConfigurationAdmin 实现了一个组件来更新此属性

public class ControllerReconfiguration {

private ConfigurationAdmin m_configAdmin;

@SuppressWarnings({ "rawtypes", "unchecked" })
public void reconfigure() throws IOException {
    Configuration configuration = m_configAdmin.getConfiguration("hello","file:./helloComponent.jar");
    configuration.setBundleLocation("file:./helloComponent.jar");
    Properties props = new Properties();
    //Dictionary props = new Hashtable();
    props.put("id1", "AA");
    configuration.update(props);
    System.out.println("Update");       

}
}

但是,此 ControllerReconfiguration 组件无法更新 'hello' 实例中的值 'A'(通过 'AA')。

请问如何修改这个ControllerReconfiguration组件?

感谢您的帮助。

【问题讨论】:

    标签: ipojo


    【解决方案1】:

    很遗憾,您不能像这样推送新的“来自”配置。

    但是,您可以直接使用 iPOJO 内省 API:http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-ipojo-introspection-api.html

    1. 检索实例的架构服务
    2. 检索 InstanceDescription 和 DependencyDescription
    3. 调用 setFilter 方法

    【讨论】:

      【解决方案2】:

      谢谢克莱门特,

      效果很好!!!!!!! :) 我使用 Factory 访问 InstanceManager。

      例如,为了访问组件“hello.call.CallHello”的InstanceManager

      @require
      private Factory[] factories;
      for (Factory factory : factories) {
                          /*
                           * "hello.call.CallHello" is a component name
                           * note: it is not component instance name
                           */
      
                          if (factory.getName().equals("hello.call.CallHello")) {
                              /*
                               * a component can have many instances
                               * if there is only one instance.
                               * get(0) return the first instance.
                               */
                              InstanceManager im = (InstanceManager) factory.getInstances().get(0);
      }
      

      【讨论】:

        猜你喜欢
        • 2014-08-15
        • 1970-01-01
        • 2012-11-08
        • 2021-02-25
        • 2016-10-31
        • 2011-09-09
        • 2021-11-29
        • 2011-03-06
        • 2021-06-16
        相关资源
        最近更新 更多