You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/03/23 21:37:47 UTC
svn commit: r1580607 - in
/commons/proper/configuration/branches/immutableNodes/src:
main/java/org/apache/commons/configuration/SubnodeConfiguration.java
test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
Author: oheger
Date: Sun Mar 23 20:37:47 2014
New Revision: 1580607
URL: http://svn.apache.org/r1580607
Log:
Added a close() method to SubnodeConfiguration.
This method delegates to the close() method of the underlying TrackedNodeModel.
Modified:
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java?rev=1580607&r1=1580606&r2=1580607&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java (original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java Sun Mar 23 20:37:47 2014
@@ -123,7 +123,6 @@ public class SubnodeConfiguration extend
* Creates a new instance of {@code SubnodeConfiguration} and initializes it
* with all relevant properties.
*
- *
* @param parent the parent configuration
* @param model the {@code TrackedNodeModel} to be used for this configuration
* @throws IllegalArgumentException if a required argument is missing
@@ -167,6 +166,19 @@ public class SubnodeConfiguration extend
}
/**
+ * Closes this sub configuration. This method closes the underlying
+ * {@link TrackedNodeModel}, thus causing the tracked node acting as root
+ * node to be released. Per default, this happens automatically when the
+ * model is claimed by the garbage collector. By calling this method
+ * explicitly, it can be indicated that this configuration is no longer used
+ * and that resources used by it can be freed immediately.
+ */
+ public void close()
+ {
+ (getTrackedModel()).close();
+ }
+
+ /**
* {@inheritDoc} This implementation returns a copy of the current node
* model with the same settings. However, it has to be ensured that the
* track count for the node selector is increased.
@@ -199,6 +211,17 @@ public class SubnodeConfiguration extend
@Override
protected InMemoryNodeModel getSubConfigurationParentModel()
{
- return ((TrackedNodeModel) getModel()).getParentModel();
+ return getTrackedModel().getParentModel();
+ }
+
+ /**
+ * Convenience method that returns the tracked model used by this sub
+ * configuration.
+ *
+ * @return the {@code TrackedNodeModel}
+ */
+ private TrackedNodeModel getTrackedModel()
+ {
+ return (TrackedNodeModel) getModel();
}
}
Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java?rev=1580607&r1=1580606&r2=1580607&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java (original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java Sun Mar 23 20:37:47 2014
@@ -39,6 +39,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.tree.NodeStructureHelper;
import org.apache.commons.configuration.tree.TrackedNodeModel;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
+import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
@@ -501,4 +502,20 @@ public class TestSubnodeConfiguration
assertTrue("Wrong finalize flag",
subModel.isReleaseTrackedNodeOnFinalize());
}
+
+ /**
+ * Tests whether the configuration can be closed.
+ */
+ @Test
+ public void testClose()
+ {
+ TrackedNodeModel model = EasyMock.createMock(TrackedNodeModel.class);
+ EasyMock.expect(model.getSelector()).andReturn(SELECTOR).anyTimes();
+ model.close();
+ EasyMock.replay(model);
+
+ SubnodeConfiguration config = new SubnodeConfiguration(parent, model);
+ config.close();
+ EasyMock.verify(model);
+ }
}