[exo-jcr-commits] exo-jcr SVN: r2980 - in kernel/branches/2.2.x/exo.kernel.container/src: test/java/org/exoplatform/container and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Aug 24 02:46:53 EDT 2010
Author: nfilotto
Date: 2010-08-24 02:46:52 -0400 (Tue, 24 Aug 2010)
New Revision: 2980
Modified:
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java
kernel/branches/2.2.x/exo.kernel.container/src/test/resources/org/exoplatform/container/test-exo-container.xml
Log:
EXOJCR-916: Duplicate instantiations are still possible however only the first corresponding instance will be kept, the other one will be available for the GC.
Modified: kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
===================================================================
--- kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java 2010-08-24 06:43:50 UTC (rev 2979)
+++ kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java 2010-08-24 06:46:52 UTC (rev 2980)
@@ -91,7 +91,14 @@
}
// Please note that we cannot fully initialize the Object "instance_" before releasing other
// threads because it could cause StackOverflowError due to recursive calls
- instance_ = exocontainer.createComponent(getComponentImplementation(), params);
+ Object instance = exocontainer.createComponent(getComponentImplementation(), params);
+ if (instance_ != null)
+ {
+ // Avoid instantiating twice the same component in case of a cyclic reference due
+ // to component plugins
+ return instance_;
+ }
+ instance_ = instance;
}
if (debug)
Modified: kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java
===================================================================
--- kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java 2010-08-24 06:43:50 UTC (rev 2979)
+++ kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java 2010-08-24 06:46:52 UTC (rev 2980)
@@ -76,6 +76,16 @@
assertEquals(value, plugin.myClass_);
}
+ public void testCyclicRef()
+ {
+ final RootContainer container = createRootContainer("test-exo-container.xml", "testCyclicRef");
+ A a = (A)container.getComponentInstanceOfType(A.class);
+ assertNotNull(a);
+ B b = (B)container.getComponentInstanceOfType(B.class);
+ assertNotNull(b);
+ assertEquals(a, b.a);
+ }
+
public void testCache()
{
URL rootURL = getClass().getResource("test-exo-container.xml");
@@ -461,4 +471,32 @@
}
}
+
+ public static class A
+ {
+ public B b;
+ public A(B b)
+ {
+ this.b = b;
+ }
+ }
+ public static class BPlugin extends BaseComponentPlugin
+ {
+ public A a;
+ public BPlugin(A a)
+ {
+ this.a = a;
+ }
+ }
+
+ public static class B
+ {
+ public A a;
+ public BPlugin plugin_;
+ public void add(BPlugin plugin)
+ {
+ this.plugin_ = plugin;
+ this.a = plugin.a;
+ }
+ }
}
\ No newline at end of file
Modified: kernel/branches/2.2.x/exo.kernel.container/src/test/resources/org/exoplatform/container/test-exo-container.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.container/src/test/resources/org/exoplatform/container/test-exo-container.xml 2010-08-24 06:43:50 UTC (rev 2979)
+++ kernel/branches/2.2.x/exo.kernel.container/src/test/resources/org/exoplatform/container/test-exo-container.xml 2010-08-24 06:46:52 UTC (rev 2980)
@@ -45,4 +45,17 @@
</component-plugin>
</component-plugins>
</component>
+ <component profiles="testCyclicRef">
+ <type>org.exoplatform.container.TestExoContainer$A</type>
+ </component>
+ <component profiles="testCyclicRef">
+ <type>org.exoplatform.container.TestExoContainer$B</type>
+ <component-plugins>
+ <component-plugin>
+ <name>testCyclicRef</name>
+ <set-method>add</set-method>
+ <type>org.exoplatform.container.TestExoContainer$BPlugin</type>
+ </component-plugin>
+ </component-plugins>
+ </component>
</configuration>
\ No newline at end of file
More information about the exo-jcr-commits
mailing list