diff options
author | Maros Marsalek <maros.mars@gmail.com> | 2017-09-04 14:37:57 +0200 |
---|---|---|
committer | Maroš Maršalek <maros.mars@gmail.com> | 2017-09-05 11:18:28 +0000 |
commit | 0d4a04e1452e19ce96c308cd45a430a3f5b72f04 (patch) | |
tree | 22f71b904209922ad2a3f8ed77f0e647346196db | |
parent | 6506878ae7ad2b9ade390127ece11f7a1a3b67dd (diff) |
Make DataModification closeable
and close the modification from transactions.
This enables cleanup of underlay resources per transaction.
It is not needed when managing VPP, but might be useful for
other use-cases where underlay transactions are involved.
Change-Id: If14197052172be0158fd7efb5ee1794935d576bc
Signed-off-by: Maros Marsalek <maros.mars@gmail.com>
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 6e903a4e2..22fba0f53 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 e21098a3b..dcd456a27 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 93043ce07..ce0e3c6fb 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; } |