Implement AsyncWriteTransaction.commit()
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / ProxyDOMDataBroker.java
index 893782feb729d2e1827b1cb8297042c74ae4433a..1c7429a45cf3893eaf60f21f2b21e9af90c63b0c 100644 (file)
@@ -12,15 +12,13 @@ import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
-import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
 import java.util.Collections;
 import java.util.Map;
 import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
@@ -35,8 +33,6 @@ import org.opendaylight.netconf.topology.singleton.messages.transactions.NewRead
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionRequest;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import scala.concurrent.Await;
 import scala.concurrent.Future;
 
@@ -67,58 +63,60 @@ public class ProxyDOMDataBroker implements DOMDataBroker {
     @Override
     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
         final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewReadTransactionRequest(), askTimeout);
+        final Object msg;
         try {
-            final Object msg = Await.result(txActorFuture, askTimeout.duration());
-            if (msg instanceof Throwable) {
-                throw (Throwable) msg;
-            }
-            Preconditions.checkState(msg instanceof NewReadTransactionReply);
-            final NewReadTransactionReply reply = (NewReadTransactionReply) msg;
-            return new ProxyReadTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
-        } catch (final Throwable t) {
-            throw new IllegalStateException("Can't create ProxyReadTransaction", t);
+            msg = Await.result(txActorFuture, askTimeout.duration());
+        } catch (Exception e) {
+            throw new IllegalStateException("Can't create ProxyReadTransaction", e);
         }
+
+        if (msg instanceof Exception) {
+            throw new IllegalStateException("Can't create ProxyReadTransaction", (Exception) msg);
+        }
+
+        Verify.verify(msg instanceof NewReadTransactionReply);
+        final NewReadTransactionReply reply = (NewReadTransactionReply) msg;
+        return new ProxyReadTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public DOMDataReadWriteTransaction newReadWriteTransaction() {
         final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewReadWriteTransactionRequest(), askTimeout);
+        final Object msg;
         try {
-            final Object msg = Await.result(txActorFuture, askTimeout.duration());
-            if (msg instanceof Throwable) {
-                throw (Throwable) msg;
-            }
-            Preconditions.checkState(msg instanceof NewReadWriteTransactionReply);
-            final NewReadWriteTransactionReply reply = (NewReadWriteTransactionReply) msg;
-            return new ProxyReadWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
-        } catch (final Throwable t) {
-            throw new IllegalStateException("Can't create ProxyReadTransaction", t);
+            msg = Await.result(txActorFuture, askTimeout.duration());
+        } catch (Exception e) {
+            throw new IllegalStateException("Can't create ProxyReadWriteTransaction", e);
+        }
+
+        if (msg instanceof Exception) {
+            throw new IllegalStateException("Can't create ProxyReadWriteTransaction", (Exception) msg);
         }
+
+        Verify.verify(msg instanceof NewReadWriteTransactionReply);
+        final NewReadWriteTransactionReply reply = (NewReadWriteTransactionReply) msg;
+        return new ProxyReadWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public DOMDataWriteTransaction newWriteOnlyTransaction() {
         final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewWriteTransactionRequest(), askTimeout);
+        final Object msg;
         try {
-            final Object msg = Await.result(txActorFuture, askTimeout.duration());
-            if (msg instanceof Throwable) {
-                throw (Throwable) msg;
-            }
-            Preconditions.checkState(msg instanceof NewWriteTransactionReply);
-            final NewWriteTransactionReply reply = (NewWriteTransactionReply) msg;
-            return new ProxyWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
-        } catch (final Throwable t) {
-            throw new IllegalStateException("Can't create ProxyWriteTransaction", t);
+            msg = Await.result(txActorFuture, askTimeout.duration());
+        } catch (Exception e) {
+            throw new IllegalStateException("Can't create ProxyWriteTransaction", e);
         }
-    }
 
-    @Override
-    public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(
-            final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener,
-            final DataChangeScope triggeringScope) {
-        throw new UnsupportedOperationException(id + ": Data change listeners not supported for netconf mount point");
+        if (msg instanceof Exception) {
+            throw new IllegalStateException("Can't create ProxyWriteTransaction", (Exception) msg);
+        }
+
+        Verify.verify(msg instanceof NewWriteTransactionReply);
+        final NewWriteTransactionReply reply = (NewWriteTransactionReply) msg;
+        return new ProxyWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
     }
 
     @Override