1

I have a component declared as:

<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>

The jar file of this component :helloComponent.jar

Now, i want to update (value="A") to (value="AA"). Thus, i implement a component using ConfigurationAdmin to update this property

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");       

}
}

However, this ControllerReconfiguration component can't update the value 'A' (by 'AA') in 'hello' instance.

How to modify this ControllerReconfiguration component, please ?

Thanks you for your help.

HNT
  • 147
  • 1
  • 10

2 Answers2

1

Unfortunately, you can't push new 'from' configuration like this.

However, you can use the iPOJO introspection API directly: http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-ipojo-introspection-api.html

  1. Retrieve the Architecture service of the instance
  2. Retrieve the InstanceDescription and DependencyDescription
  3. Call the setFilter method
Clement
  • 2,817
  • 1
  • 12
  • 11
0

Thanks Clement,

it works fine !!!!! :) I access InstanceManager using Factory.

Ex, in order to access InstanceManager of component "hello.call.CallHello"

@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);
}
HNT
  • 147
  • 1
  • 10