NanoContainer
  1. NanoContainer
  2. NANO-170

Problem with Nanocontainer XML script start with components having cyclic dependencies

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.0
    • Fix Version/s: None
    • Component/s: xml
    • Labels:
      None
    • Environment:
      jdk 1.5.0_05
    • Number of attachments :
      2

      Description

      Reference: Mail [picocontainer-user] Re: Hotswap with Nanocontainer XML scripting possible?

      This is nearly the same component configuration like the
      'cbrcp.container.CBRCPAbstractContainer'(pls see ./src/cbrcp/container/CBRCPAbstractContainer
      in zip) which works perfectly. The difference
      in the XML script is that some components which has no cyclic dependencies
      are added as "component-implementation" to the container. The result from
      the script is that all components which are added via "component-adapter"
      are NOT started. For testing I changed the other ("component-implementation")
      to "component-adapter" and they are not started either.

      Next thing I tried out, was changing

      <component-adapter-factory key="CBRCPFactory" class="org.picocontainer.defaults.CachingComponentAdapterFactory">
      <component-adapter-factory class="org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory">
      <component-adapter-factory class="org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory" />
      </component-adapter-factory>
      </component-adapter-factory>

      to

      <component-adapter-factory key="CBRCPFactory" class="org.picocontainer.defaults.HotSwappingComponentAdapterFactory">
      <component-adapter-factory class="org.picocontainer.gems.adapters.CachingComponentAdapterFactory">
      <component-adapter-factory class="org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory"/>
      </component-adapter-factory>
      </component-adapter-factory>

      which complies with my class 'CBRCPHotSwappingComponentAdapterFactory.java'
      (pls see below again), but this produces only the following exception:

      #Exception begin===========================================================

      Exception in thread "main" org.nanocontainer.script.NanoContainerMarkupException: Class not found:
      'org.picocontainer.gems.adapters.CachingComponentAdapterFactory' classloader stack
      [org.picocontainer.defaults.CustomPermissionsURLClassLoader 27338224:
      sun.misc.Launcher$AppClassLoader@133056f
      sun.misc.Launcher$ExtClassLoader@a9c85c
      ]
      at org.nanocontainer.script.xml.XMLContainerBuilder.populateContainer(XMLContainerBuilder.java:166)
      at org.nanocontainer.script.xml.XMLContainerBuilder.createContainerFromScript(XMLContainerBuilder.java:140)
      at org.nanocontainer.script.ScriptedContainerBuilder.createContainer(ScriptedContainerBuilder.java:60)
      at org.nanocontainer.integrationkit.LifecycleContainerBuilder.buildContainer(LifecycleContainerBuilder.java:26)
      at cbrcp.CBRCPStarter.startByNanocontainer(CBRCPStarter.java:110)
      at cbrcp.CBRCPStarter.setupContainer(CBRCPStarter.java:76)
      at cbrcp.CBRCPStarter.main(CBRCPStarter.java:42)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      Caused by: java.lang.ClassNotFoundException:
      'org.picocontainer.gems.adapters.CachingComponentAdapterFactory' classloader stack
      [org.picocontainer.defaults.CustomPermissionsURLClassLoader 27338224:
      sun.misc.Launcher$AppClassLoader@133056f
      sun.misc.Launcher$ExtClassLoader@a9c85c
      ]
      at org.picocontainer.defaults.CustomPermissionsURLClassLoader.decorateException(CustomPermissionsURLClassLoader.java:71)
      at org.picocontainer.defaults.CustomPermissionsURLClassLoader.loadClass(CustomPermissionsURLClassLoader.java:42)
      at org.nanocontainer.script.xml.XMLContainerBuilder.registerComponentImplementation(XMLContainerBuilder.java:308)
      at org.nanocontainer.script.xml.XMLContainerBuilder.addComponentAdapterFactory(XMLContainerBuilder.java:245)
      at org.nanocontainer.script.xml.XMLContainerBuilder.addComponentAdapterFactory(XMLContainerBuilder.java:234)
      at org.nanocontainer.script.xml.XMLContainerBuilder.registerComponentsAndChildContainers(XMLContainerBuilder.java:204)
      at org.nanocontainer.script.xml.XMLContainerBuilder.populateContainer(XMLContainerBuilder.java:164)
      ... 11 more

      #Exception end===========================================================

      My classpath seems to be correct, so the components would not start via the
      extended DefaultPicoContainer. I got really stuck. Does these problems say
      something to you...?

        Activity

        Hide
        Jens Krefeldt added a comment -

        Sorry forgotten, unzip attachment and open project in IDEA. compile and run. Presets are starting application from XML script incorrectly (i.e only the "component-implementation" defined components). To start the Picocontainer make a comment before

        containerSetupFile=./container-config/start-container-setup.xml

        in file './cbrcp-start.properties. This will launch the application correctly.

        Show
        Jens Krefeldt added a comment - Sorry forgotten, unzip attachment and open project in IDEA. compile and run. Presets are starting application from XML script incorrectly (i.e only the "component-implementation" defined components). To start the Picocontainer make a comment before containerSetupFile=./container-config/start-container-setup.xml in file './cbrcp-start.properties. This will launch the application correctly.
        Hide
        Mauro Talevi added a comment -

        Changed fix version from 1.0

        Show
        Mauro Talevi added a comment - Changed fix version from 1.0
        Mauro Talevi made changes -
        Field Original Value New Value
        Fix Version/s 1.0 [ 10148 ]
        Summary Problem with Nanocontainer XML script start with components having cyclic dependencies (Reference: Mail [picocontainer-user] Re: Hotswap with Nanocontainer XML scripting possible?) Problem with Nanocontainer XML script start with components having cyclic dependencies
        Type Task [ 3 ] Bug [ 1 ]
        Hide
        Mauro Talevi added a comment -

        Jens,
        I've added a test case for this issue:
        container/src/test/org/nanocontainer/script/xml/issues/Issue0170TestCase

        It seems to be you may have gotten the package names wrong. The following works:

        <component-adapter-factory key='factory' class='org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory'>
        <component-adapter-factory class='org.picocontainer.defaults.CachingComponentAdapterFactory'/>
        <component-adapter-factory class='org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory'/>
        </component-adapter-factory>

        Please let us know if this is the case. If not, please amend the test case as appropriate
        so that it fails and attach a patch that we can look at.

        Thanks

        Show
        Mauro Talevi added a comment - Jens, I've added a test case for this issue: container/src/test/org/nanocontainer/script/xml/issues/Issue0170TestCase It seems to be you may have gotten the package names wrong. The following works: <component-adapter-factory key='factory' class='org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory'> <component-adapter-factory class='org.picocontainer.defaults.CachingComponentAdapterFactory'/> <component-adapter-factory class='org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory'/> </component-adapter-factory> Please let us know if this is the case. If not, please amend the test case as appropriate so that it fails and attach a patch that we can look at. Thanks
        Hide
        Jens Krefeldt added a comment -

        Hi,

        here are test cases which solves problem.

        My mistake was, that I misinterpreted Jörg's example script

        <container>
        <component-adapter-factory key="connectionFactory" class="org.picocontainer.defaults.CachingComponentAdapterFactory">
        <component-adapter-factory class="org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory">
        <component-adapter-factory class="org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory" />
        </component-adapter-factory>
        </component-adapter-factory>
        <container>
        <component-implementation class="company.ldap.config.Configurator">
        <parameter/>
        <parameter><string>standard</string></parameter>
        </component-implementation>
        <component-adapter class-name-key="company.ldap.LDAPConnection" class="company.ldap.LDAPProviderTest$LDAPConnectionMock" factory="connectionFactory" />
        </container>
        </container>

        i.e. especially the line with "<component-adapter class-name-key="company.ldap.LDAPConnection...". I thought that "class-name-key" is the key a component is registered with the container, but I think this is the class name for your special component adapter, isnt it. So I used this as key, but I had to use the attribute "key" of "component-adapter" element. So I changed this and it worked fine.

        Mauro, in my test suite your hint:

        <component-adapter-factory key='factory' class='org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory'>
        <component-adapter-factory class='org.picocontainer.defaults.CachingComponentAdapterFactory'/>
        <component-adapter-factory class='org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory'/>
        </component-adapter-factory>

        does not work. In this case an UnsatisfiableDependenciesException is thrown for the HotswappingCompentAdapter itself!

        The solution is:

        <component-adapter-factory key='factory' class='org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory'>
        <component-adapter-factory class='org.picocontainer.defaults.CachingComponentAdapterFactory'>
        <component-adapter-factory class='org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory'/>
        </component-adapter-factory>
        </component-adapter-factory>

        with a component definition like

        <component-adapter key='test.ADependsOnB' class='test.ADependsOnBImpl' factory='factory'>
        <parameter key='test.BDependsOnA'>
        <class>test.BDependsOnAImpl</class>
        </parameter>
        </component-adapter>
        ....

        But many thx for your help. Pico and Nano rules!

        Greetings

        Jens

        Show
        Jens Krefeldt added a comment - Hi, here are test cases which solves problem. My mistake was, that I misinterpreted Jörg's example script <container> <component-adapter-factory key="connectionFactory" class="org.picocontainer.defaults.CachingComponentAdapterFactory"> <component-adapter-factory class="org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory"> <component-adapter-factory class="org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory" /> </component-adapter-factory> </component-adapter-factory> <container> <component-implementation class="company.ldap.config.Configurator"> <parameter/> <parameter><string>standard</string></parameter> </component-implementation> <component-adapter class-name-key="company.ldap.LDAPConnection" class="company.ldap.LDAPProviderTest$LDAPConnectionMock" factory="connectionFactory" /> </container> </container> i.e. especially the line with "<component-adapter class-name-key="company.ldap.LDAPConnection...". I thought that "class-name-key" is the key a component is registered with the container, but I think this is the class name for your special component adapter, isnt it. So I used this as key, but I had to use the attribute "key" of "component-adapter" element. So I changed this and it worked fine. Mauro, in my test suite your hint: <component-adapter-factory key='factory' class='org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory'> <component-adapter-factory class='org.picocontainer.defaults.CachingComponentAdapterFactory'/> <component-adapter-factory class='org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory'/> </component-adapter-factory> does not work. In this case an UnsatisfiableDependenciesException is thrown for the HotswappingCompentAdapter itself! The solution is: <component-adapter-factory key='factory' class='org.picocontainer.gems.adapters.HotSwappingComponentAdapterFactory'> <component-adapter-factory class='org.picocontainer.defaults.CachingComponentAdapterFactory'> <component-adapter-factory class='org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory'/> </component-adapter-factory> </component-adapter-factory> with a component definition like <component-adapter key='test.ADependsOnB' class='test.ADependsOnBImpl' factory='factory'> <parameter key='test.BDependsOnA'> <class>test.BDependsOnAImpl</class> </parameter> </component-adapter> .... But many thx for your help. Pico and Nano rules! Greetings Jens
        Jens Krefeldt made changes -
        Attachment testcase-src.zip [ 18817 ]
        Hide
        Mauro Talevi added a comment -

        Jens, glad we could help to solve your issue.

        Show
        Mauro Talevi added a comment - Jens, glad we could help to solve your issue.
        Mauro Talevi made changes -
        Resolution Won't Fix [ 2 ]
        Status Open [ 1 ] Resolved [ 5 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Jens Krefeldt
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: