Correct exception handling in LegacyDOMDataBrokerAdapter 24/76524/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 1 Oct 2018 09:50:13 +0000 (11:50 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 1 Oct 2018 09:50:13 +0000 (11:50 +0200)
When a TransactionChain is closed, we need to make sure we throw
the correct (controller) exception instead of re-wrapping the mdsal
one.

Change-Id: I74434115fe14a18ba520fc789fa8a21d932a4a15
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-dom-compat/src/main/java/org/opendaylight/controller/sal/core/compat/LegacyDOMDataBrokerAdapter.java

index 9d68bd3..2367244 100644 (file)
@@ -20,6 +20,7 @@ import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Supplier;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.api.MappingCheckedFuture;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
@@ -27,6 +28,7 @@ import org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableEx
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener;
@@ -180,17 +182,17 @@ public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMD
         legacyChain.set(new DOMTransactionChain() {
             @Override
             public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
-                return new DOMDataReadOnlyTransactionAdapter(delegateChain.newReadOnlyTransaction());
+                return new DOMDataReadOnlyTransactionAdapter(wrapException(delegateChain::newReadOnlyTransaction));
             }
 
             @Override
             public DOMDataReadWriteTransaction newReadWriteTransaction() {
-                return new DOMDataTransactionAdapter(delegateChain.newReadWriteTransaction());
+                return new DOMDataTransactionAdapter(wrapException(delegateChain::newReadWriteTransaction));
             }
 
             @Override
             public DOMDataWriteTransaction newWriteOnlyTransaction() {
-                return new DOMDataTransactionAdapter(delegateChain.newWriteOnlyTransaction());
+                return new DOMDataTransactionAdapter(wrapException(delegateChain::newWriteOnlyTransaction));
             }
 
             @Override
@@ -202,6 +204,14 @@ public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMD
         return legacyChain.get();
     }
 
+    static <T> T wrapException(final Supplier<T> supplier) {
+        try {
+            return supplier.get();
+        } catch (org.opendaylight.mdsal.common.api.TransactionChainClosedException e) {
+            throw new TransactionChainClosedException("Transaction chain already closed", e);
+        }
+    }
+
     private static class DOMDataTransactionAdapter implements DOMDataReadWriteTransaction {
         private final DOMDataTreeReadTransaction readDelegate;
         private final DOMDataTreeWriteTransaction writeDelegate;

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.