You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Pierre De Rop (JIRA)" <ji...@apache.org> on 2012/10/05 08:56:47 UTC

[jira] [Created] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Pierre De Rop created FELIX-3700:
------------------------------------

             Summary: DS Factory Components don't support configuration-policy = require
                 Key: FELIX-3700
                 URL: https://issues.apache.org/jira/browse/FELIX-3700
             Project: Felix
          Issue Type: Bug
          Components: Declarative Services (SCR)
         Environment: linux, jdk1.6
            Reporter: Pierre De Rop


With scr 1.6.0 and also with scr from trunk, there is the following problem:

When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.

This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.

For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).

I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.

Am I correct or does the spec forbid factory components to use the configuration-policy = require ?

->

@Component(factory = "A", configurationPolicy = ConfigurationPolicy.require)
public class A {
  @Activate
  void start(Map<?, ?> config) {
    System.out.println("A.start:" + config.get("foo");
  }
}

@Component
public class Main {
  private ConfigurationAdmin _cm;
  
  @Reference(type = '*', target = "(component.factory=A)")
  void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
    System.out.println("Main.bindCF");
    cf.newInstance(null);
  }
  
  @Reference
  void bindCM(ConfigurationAdmin cm) {
    _cm = cm;
  }
  
  @Activate
  void start() {
    System.out.println("Main.start");
    
    new Thread(new Runnable() {
      public void run() {
        try {
          Thread.sleep(1000);
          System.out.println("Configuring A");          
          Configuration config = _cm.getConfiguration("A", null);
          config.update(new Hashtable() {
            {
              put("foo", "bar");
            }
          });          
        } catch (Exception ioe) {
          ioe.printStackTrace();
        }
      }
    }).start();
  }
}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13477690#comment-13477690 ] 

Pierre De Rop commented on FELIX-3700:
--------------------------------------

Thanks for clarifying, I was not sure what should be done.

Actually, I've been confused by the following comment, in ComponentFactoryTest.test_component_factory_require_configuration():

->
    @Test
    public void test_component_factory_require_configuration() throws InvalidSyntaxException
        ...
        // delete config, ensure factory still active and component instance, not changed


... Ok, I do agree with you and I'll commit a fix in order to remove the component factory (but not the created component instances), and will also change the test.




                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470599#comment-13470599 ] 

Felix Meschberger commented on FELIX-3700:
------------------------------------------

A Component Factory can take configuration just as any configuration and this configuration is inherited by all instances (though existing instances are not updated IIRC).

>From reading the code, I would think this should work ...

But then: we have a test (test_component_factory_require_configuration) but it looks like this test is implemented wrong and expects a Factory Component requiring configuration to be active even if no configuration is available.
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "David Jencks (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13475926#comment-13475926 ] 

David Jencks commented on FELIX-3700:
-------------------------------------

Section 112.7 does clearly say that a component factory can be configured by config admin.  I don't understand why it says you can't use a factory pid with a component factory.  Wouldn't this just give you one component factory per configuration?

I haven't tried your patch but I don't really understand why you need the new variable.  What happens if you leave it out?

It also looks to me as if ComponentFactoryImpl.getProperties is wrong in the presence of a configuration that overrides some target properties from the metadata.  Is this the additional problem you saw?
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Assigned] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop reassigned FELIX-3700:
------------------------------------

    Assignee: Pierre De Rop
    
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>            Assignee: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470647#comment-13470647 ] 

Pierre De Rop commented on FELIX-3700:
--------------------------------------

Oops felix, I missed your response.

Yes, I do agree that may be there is a problem with the test_component_factory_require_configuration.
I actually started to modify it in order to reproduce the problem, but I have not yet finished.


                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop updated FELIX-3700:
---------------------------------

    Attachment: ComponentFactoryTest.java

attached a modified version of the ComponentFactoryTest.java with a new added method
test_component_factory_require_configuration2().

With the patch, the test_component_factory_require_configuration2() works and the old test_component_factory_require_configuration() test is failing.

Without the patch, the old method works and the new configuration2() is failing.
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "David Jencks (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13477448#comment-13477448 ] 

David Jencks commented on FELIX-3700:
-------------------------------------

I may not understand what you are saying.  I see in the spec 112.2.4

Any component configurations activated via the component factory are unaffected by the unregistration of the Component Factory service, but may themselves become unsatisfied for the same reason.

I think that, in the situation where the component factory has configuration required,  the component factory service must be unregistered if the required configuration is removed, but none of the components created by calling factory.newInstance should be removed.
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "David Jencks (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13475926#comment-13475926 ] 

David Jencks edited comment on FELIX-3700 at 10/15/12 1:05 AM:
---------------------------------------------------------------

Section 112.7 does clearly say that a component factory can be configured by config admin.  I don't understand why it says you can't use a factory pid with a component factory.  Wouldn't this just give you one component factory per configuration?

I haven't tried your patch but I don't really understand why you need the new variable.  What happens if you leave it out?

It also looks to me as if ComponentFactoryImpl.getProperties is wrong in the presence of a configuration that overrides some target properties from the metadata.  Is this the additional problem you saw?

The locking looks correct to me.
                
      was (Author: djencks):
    Section 112.7 does clearly say that a component factory can be configured by config admin.  I don't understand why it says you can't use a factory pid with a component factory.  Wouldn't this just give you one component factory per configuration?

I haven't tried your patch but I don't really understand why you need the new variable.  What happens if you leave it out?

It also looks to me as if ComponentFactoryImpl.getProperties is wrong in the presence of a configuration that overrides some target properties from the metadata.  Is this the additional problem you saw?
                  
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "David Jencks (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13477115#comment-13477115 ] 

David Jencks commented on FELIX-3700:
-------------------------------------

I think the read lock should be sufficient.
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop updated FELIX-3700:
---------------------------------

    Description: 
With scr 1.6.0 and also with scr from trunk, there is the following problem:

When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.

This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.

For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).

I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.

Am I correct or does the spec forbid factory components to use the configuration-policy = require ?

->

@Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
public class A {
  @Activate
  void start(Map<?, ?> config) {
    System.out.println("A.start:" + config.get("foo");
  }
}

@Component
public class Main {
  private ConfigurationAdmin _cm;
  
  @Reference(type = '*', target = "(component.factory=A)")
  void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
    System.out.println("Main.bindCF");
    cf.newInstance(null);
  }
  
  @Reference
  void bindCM(ConfigurationAdmin cm) {
    _cm = cm;
  }
  
  @Activate
  void start() {
    System.out.println("Main.start");
    
    new Thread(new Runnable() {
      public void run() {
        try {
          Thread.sleep(1000);
          System.out.println("Configuring A");          
          Configuration config = _cm.getConfiguration("A", null);
          config.update(new Hashtable() {
            {
              put("foo", "bar");
            }
          });          
        } catch (Exception ioe) {
          ioe.printStackTrace();
        }
      }
    }).start();
  }
}


  was:
With scr 1.6.0 and also with scr from trunk, there is the following problem:

When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.

This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.

For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).

I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.

Am I correct or does the spec forbid factory components to use the configuration-policy = require ?

->

@Component(factory = "A", configurationPolicy = ConfigurationPolicy.require)
public class A {
  @Activate
  void start(Map<?, ?> config) {
    System.out.println("A.start:" + config.get("foo");
  }
}

@Component
public class Main {
  private ConfigurationAdmin _cm;
  
  @Reference(type = '*', target = "(component.factory=A)")
  void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
    System.out.println("Main.bindCF");
    cf.newInstance(null);
  }
  
  @Reference
  void bindCM(ConfigurationAdmin cm) {
    _cm = cm;
  }
  
  @Activate
  void start() {
    System.out.println("Main.start");
    
    new Thread(new Runnable() {
      public void run() {
        try {
          Thread.sleep(1000);
          System.out.println("Configuring A");          
          Configuration config = _cm.getConfiguration("A", null);
          config.update(new Hashtable() {
            {
              put("foo", "bar");
            }
          });          
        } catch (Exception ioe) {
          ioe.printStackTrace();
        }
      }
    }).start();
  }
}


    
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13477441#comment-13477441 ] 

Pierre De Rop edited comment on FELIX-3700 at 10/16/12 11:03 PM:
-----------------------------------------------------------------

Committed a patch in revision 1399033.

So, the component factory is not registered until the configuration is available (if policy=require),
and the target filters are updated in case the configuration is updated and the state is either DISABLE or UNSATISFIED.

For now, when the configuration is removed, I don't unregister the component factory and any created component instances.
Indeed, in the ComponentFactoryTest.test_component_factory_require_configuration() test, it sounds like Felix does not expect the component factory to be unregistered automatically when configuration is lost.



                
      was (Author: pderop):
    Committed a patch in revision 1399033.

So, the component factory is not registered the configuration is available (if policy=require),
and the target filters are updated in case the configuration is updated and the state is either DISABLE or UNSATISFIED.

For now, when the configuration is removed, I don't unregister the component factory and any created component instances.
Indeed, in the ComponentFactoryTest.test_component_factory_require_configuration() test, it sounds like Felix does not expect the component factory to be unregistered automatically when configuration is lost.



                  
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13477441#comment-13477441 ] 

Pierre De Rop commented on FELIX-3700:
--------------------------------------

Committed a patch in revision 1399033.

So, the component factory is not registered the configuration is available (if policy=require),
and the target filters are updated in case the configuration is updated and the state is either DISABLE or UNSATISFIED.

For now, when the configuration is removed, I don't unregister the component factory and any created component instances.
Indeed, in the ComponentFactoryTest.test_component_factory_require_configuration() test, it sounds like Felix does not expect the component factory to be unregistered automatically when configuration is lost.



                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13477877#comment-13477877 ] 

Pierre De Rop commented on FELIX-3700:
--------------------------------------

committed in 1399224 a fix, in order to unregister the component factory if the required configuration is removed.
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "David Jencks (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13476347#comment-13476347 ] 

David Jencks commented on FELIX-3700:
-------------------------------------

I agree, configuration required should work with component factories.

I changed the enableDependencyManagers to look if configuration was required because if it is there is no point registering the service listeners to look for the reference services before we know what the target filter is.  This should be true for component factories too.  So I think that the component factory should set the target filters when it gets the configuration by calling AbstractComponentManager.updateTargets(Dictionary properties)
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop resolved FELIX-3700.
----------------------------------

    Resolution: Fixed

Committed last fix for this issue, in revision 1400265.
I think this issue is now resolved.
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>            Assignee: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13476070#comment-13476070 ] 

Pierre De Rop commented on FELIX-3700:
--------------------------------------

Thanks David for reacting;

Ok, I do agree: in section 112.7, the specification forbids to use a factory configuration pid in order to configure a DS component factory.
But this issue is not about using a factory configuration pid: it is about using a single configuration pid for configuring a DS component factory. By "single" configuration pid, I'm talking about configurations created with the "org.osgi.service.cm.ConfigurationAdmin.getConfiguration(java.lang.String pid, java.lang.String location)" method.

That beeing said, one week has passed since I posted this issue and many commits have been made ...
So I have to recheck with the current trunk, and will get back as soon as possible.


                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop updated FELIX-3700:
---------------------------------

    Attachment: FELIX-37000.patch2

Attached a cleaned version of the initial patch (I'm still using an extra "m_isConfigured" class attribute).

The patch also includes a modification made in the integration ComponentFactoryTest.

Also implemented deactivation of the ComponentFactory when configuration is lost (and when configuration policy was required).

I wonder if all created component instances (with ComponentFactory.newInstance) should also be deactivated when configuration is lost ? (I prefer to think about this a bit before committing anything. what do you think ?

 
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470642#comment-13470642 ] 

Pierre De Rop commented on FELIX-3700:
--------------------------------------

I believe I failed to explain my problem clearly ... hope you will give me another chance :-)

(I have joined a patch to this issue, it's certainly incomplete, but if you could take a look at it)

So, In our applications, we simply have the following components:

1) a component "C", which can be instantiated several times (C1/C2), but all instances are using the same configuration, from the same PID "C". For example, in the "C" configuration pid, we configure some shared informations, like a syslog address, some database addr, etc ...

C is declared like this:

@Component(name="C", factory="CFactory", configuraton-policy=require)"
class C {
   ...
}

2) we also have a "Manager" component which is in charge of instantiating C1/C2. We don't instantiate 1001 components. We are actually writing an "elastic" http container,  where DS components are dynamically created if the load increase. (such components are actually actor components). So, This "Manager" component tracks the org.osgi.service.component.ComponentFactory instances with filter "(component.factory=CFactory)" in order to instantiate C1/C2.

3) finally, we have a "Configurator" component, which loads the configuration from a database and registers it into CM (config-admin osgi service), using pid "C".

Now the problem is that if the ComponentFactory for C is registered by SCR before the configuration for the PID "C" is registered into CM, then  C1/C2 will be instantiated with an empty configuration. (because the Configuration has not yet registered it into CM).

Now,  I could probably rework the application in order to use another strategy, but I believe that the component factory for C should not be registered before the configuration pid for C is available, because C is declared with configuration-policy=require.

Please take a look at the patch
thanks in advance.

                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop updated FELIX-3700:
---------------------------------

    Attachment: FELIX-3700.patch

attached the proposed patch (it's probably incomplete, but it will give the idea of my problem).
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13476164#comment-13476164 ] 

Pierre De Rop commented on FELIX-3700:
--------------------------------------

ok, I have aligned the patch with the current trunk.

so, regarding your questions:

1) "I haven't tried your patch but I don't really understand why you need the new variable. What happens if you leave it out? "
->

the m_componentMetadata variable is used because the ComponentFactoryImpl.hasConfiguration() should return false if the config policy is required and if the configuration is not yet available. This variable is set to true when the configurationUpdated method is called (when config admin gives us the configuration).

Now, I do agree that we could avoid using this extra variable... I will manage to rework the patch without using this extra variable.

2) "It also looks to me as if ComponentFactoryImpl.getProperties is wrong in the presence of a configuration that overrides some target properties from the metadata. Is this the additional problem you saw?"

I did not find this problem but looking at the code, I do agree with you, we probably have this problem too.

Now the new problem I found is another one: Since the commit of AbstractComponentManager.java, from revision 1397887:

   http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?r1=1397886&r2=1397887

then any component factory defined with configuration-policy = require, and also with some required (and available) service dependencies remains unsatisfied.
I mean: the ComponentFactory is never registered into the registry even if the required References are available and if the configuration is also available.
I have to make an integration test for this problem ...

If we remove the "if ( !m_componentMetadata.isConfigurationRequired() )" test from the AbstractComponentManager.enableDependencyManagers method, 
then we don't have the problem:

    private void enableDependencyManagers() throws InvalidSyntaxException
    {
//        if ( !m_componentMetadata.isConfigurationRequired() )
//        {
            Iterator it = getDependencyManagers();
            while ( it.hasNext() )
            {
                DependencyManager dm = (DependencyManager) it.next();
                dm.enable();
            }
//        }
    }

I wonder why the dependency managers are not enabled if the configuration is required ?


                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop updated FELIX-3700:
---------------------------------

    Attachment: FELIX-37000.patch3

thanks David,

I applied your suggestion and it seems to work. 
I joined the FELIX-37000.patch3 diff with the modifications you suggested.
(I don't commit for now because I prefer to test this patch during a couple of days, before committing).

I have one remaining question:

It looks like the super.updateTargets(Properties) method should be invoked while holding a lock. So, I'm using a read lock. Should I use a write lock instead of a read lock ?

thanks.

                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-37000.patch2, FELIX-37000.patch3, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "Pierre De Rop (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13475910#comment-13475910 ] 

Pierre De Rop commented on FELIX-3700:
--------------------------------------

Felix,

I'm sorry about to insist, but can you please give me your opinion on this issue ?
I would like to commit the attached fix, but since David disagrees, I'm now a bit embarrassed.

I have checked the specification and I think that a component factory can inherit from config admin properties, and that the configuration-policy=require is making sense for component factories. I also checked and equinox ds is implementing configuration-policy=require with factory components (that is: a factory component is not registered if the configuration from config-admin is not available).

Can you please decide if this issue should be really closed or if I can commit ? 
(but I would like you to review the patch because I'm not sure if the locking is correctly done or not).

(I have found another problem with component factory + configuration-policy=require, but I would like to conclude about this issue, before going ahead ...)

Thanks.
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>         Attachments: ComponentFactoryTest.java, FELIX-3700.patch
>
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (FELIX-3700) DS Factory Components don't support configuration-policy = require

Posted by "David Jencks (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470532#comment-13470532 ] 

David Jencks commented on FELIX-3700:
-------------------------------------

Why do you think it makes sense to configure a component factory with config admin?  

If the factory xml configuration has a configuration pid, how does the configuration admin configuration relate to the 1001 component instances you create by calling newinstance on the factory?  How about if the factory xml specifies a factory pid?

Suppose you put a configuration pid in the properties you give the component factory.  What happens?

Suppose you put a factory pid in the properties.  What happens?

I don't think any of these scenarios make sense.  Since the spec doesn't explain what should happen I tend to think they aren't supposed to be supported.
                
> DS Factory Components don't support configuration-policy = require
> ------------------------------------------------------------------
>
>                 Key: FELIX-3700
>                 URL: https://issues.apache.org/jira/browse/FELIX-3700
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>         Environment: linux, jdk1.6
>            Reporter: Pierre De Rop
>
> With scr 1.6.0 and also with scr from trunk, there is the following problem:
> When a factory component (declared with a factory attribute in the Component element), and when the Component is also defined with configuration-policy = require, then the org.osgi.service.component.ComponentFactory associated to the factory component is registered in the OSGi registry even if the configuration for the component is not yet available.
> This is  a problem because when the org.osgi.service.component.ComponentFactory is registered in the registry, then another component using the ComponentFactory may call the newInstance method and then instantiate the component without the required configuration.
> For example, in the following code, Main is injected with the A ComponentFactory and creates immediately one A instance: but at this point, the Configuration for A has not yet been created (see in the Main.start method, where a thread is started in order to create the A configuration after 1 second ...).
> I expect A ComponentFactory to be registered only after the A Configuration is available from config admin, because the A configuration-policy has been set to the "require" value.
> Am I correct or does the spec forbid factory components to use the configuration-policy = require ?
> ->
> @Component(name="A", factory = "A", configurationPolicy = ConfigurationPolicy.require)
> public class A {
>   @Activate
>   void start(Map<?, ?> config) {
>     System.out.println("A.start:" + config.get("foo");
>   }
> }
> @Component
> public class Main {
>   private ConfigurationAdmin _cm;
>   
>   @Reference(type = '*', target = "(component.factory=A)")
>   void bindCF(ComponentFactory cf) { // should only be called once A config admin configuration is avail
>     System.out.println("Main.bindCF");
>     cf.newInstance(null);
>   }
>   
>   @Reference
>   void bindCM(ConfigurationAdmin cm) {
>     _cm = cm;
>   }
>   
>   @Activate
>   void start() {
>     System.out.println("Main.start");
>     
>     new Thread(new Runnable() {
>       public void run() {
>         try {
>           Thread.sleep(1000);
>           System.out.println("Configuring A");          
>           Configuration config = _cm.getConfiguration("A", null);
>           config.update(new Hashtable() {
>             {
>               put("foo", "bar");
>             }
>           });          
>         } catch (Exception ioe) {
>           ioe.printStackTrace();
>         }
>       }
>     }).start();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira