[ 
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

Reply via email to