summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--infra/data-api/src/main/java/io/fd/honeycomb/data/DataModification.java10
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java13
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java3
3 files changed, 21 insertions, 5 deletions
diff --git a/infra/data-api/src/main/java/io/fd/honeycomb/data/DataModification.java b/infra/data-api/src/main/java/io/fd/honeycomb/data/DataModification.java
index 6e903a4..22fba0f 100644
--- a/infra/data-api/src/main/java/io/fd/honeycomb/data/DataModification.java
+++ b/infra/data-api/src/main/java/io/fd/honeycomb/data/DataModification.java
@@ -26,7 +26,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailed
* Modification of a {@link ModifiableDataManager}.
*/
@Beta
-public interface DataModification extends ReadableDataManager {
+public interface DataModification extends ReadableDataManager, AutoCloseable {
/**
* Delete the node at specified path.
@@ -67,4 +67,12 @@ public interface DataModification extends ReadableDataManager {
* @throws DataValidationFailedException if modification data is not valid
*/
void validate() throws DataValidationFailedException;
+
+ /**
+ * Perform cleanup if necessary.
+ */
+ @Override
+ default void close() {
+ // by default, no cleanup is required
+ }
}
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java
index e21098a..dcd456a 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java
@@ -25,6 +25,7 @@ import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import io.fd.honeycomb.data.DataModification;
import io.fd.honeycomb.data.ReadableDataManager;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -43,7 +44,7 @@ final class ReadOnlyTransaction implements DOMDataReadOnlyTransaction {
@Nullable
private ReadableDataManager operationalData;
@Nullable
- private ReadableDataManager configSnapshot;
+ private DataModification configSnapshot;
private boolean closed = false;
@@ -51,7 +52,7 @@ final class ReadOnlyTransaction implements DOMDataReadOnlyTransaction {
* @param configData config data tree manager. Null if config reads are not to be supported
* @param operationalData operational data tree manager. Null if operational reads are not to be supported
*/
- private ReadOnlyTransaction(@Nullable final ReadableDataManager configData,
+ private ReadOnlyTransaction(@Nullable final DataModification configData,
@Nullable final ReadableDataManager operationalData) {
this.configSnapshot = configData;
this.operationalData = operationalData;
@@ -59,6 +60,10 @@ final class ReadOnlyTransaction implements DOMDataReadOnlyTransaction {
@Override
public synchronized void close() {
+ if(configSnapshot != null) {
+ configSnapshot.close();
+ }
+
closed = true;
configSnapshot = null;
operationalData = null;
@@ -101,12 +106,12 @@ final class ReadOnlyTransaction implements DOMDataReadOnlyTransaction {
}
@Nonnull
- static ReadOnlyTransaction createConfigOnly(@Nonnull final ReadableDataManager configData) {
+ static ReadOnlyTransaction createConfigOnly(@Nonnull final DataModification configData) {
return new ReadOnlyTransaction(requireNonNull(configData), null);
}
@Nonnull
- static ReadOnlyTransaction create(@Nonnull final ReadableDataManager configData,
+ static ReadOnlyTransaction create(@Nonnull final DataModification configData,
@Nonnull final ReadableDataManager operationalData) {
return new ReadOnlyTransaction(requireNonNull(configData), requireNonNull(operationalData));
}
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java
index 93043ce..ce0e3c6 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java
@@ -104,6 +104,9 @@ final class WriteTransaction implements DOMDataWriteTransaction {
// only NEW transactions can be cancelled
return false;
} else {
+ if (configModification != null) {
+ configModification.close();
+ }
status = CANCELED;
return true;
}