Simplify ListenableFuture translation
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / DOMRpcRouter.java
index f95ef1a9367c9cb9bd62daaeb8456a10af06a889..d78e9b9c7b45992726eccbea8b9d079d3b02629e 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.md.sal.dom.broker.impl;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
@@ -43,17 +44,24 @@ public final class DOMRpcRouter implements AutoCloseable, DOMRpcService, DOMRpcP
     private final org.opendaylight.mdsal.dom.api.DOMRpcService delegateRpcService;
     private final org.opendaylight.mdsal.dom.api.DOMRpcProviderService delegateRpcProviderService;
 
+    // Note - this is only used for backward compatibility for UTs that use the empty constructor which creates
+    // a local mdsal DOMRpcRouter that needs to be updated with the SchemaContext. In production, the mdsal API
+    // services are passed via the constructor and are set up externally with the SchemaContext.
+    private final SchemaContextListener delegateSchemaContextListener;
+
     @VisibleForTesting
     public DOMRpcRouter() {
         org.opendaylight.mdsal.dom.broker.DOMRpcRouter delegate = new org.opendaylight.mdsal.dom.broker.DOMRpcRouter();
         this.delegateRpcService = delegate.getRpcService();
         this.delegateRpcProviderService = delegate.getRpcProviderService();
+        this.delegateSchemaContextListener = delegate;
     }
 
     public DOMRpcRouter(final org.opendaylight.mdsal.dom.api.DOMRpcService delegateRpcService,
             final org.opendaylight.mdsal.dom.api.DOMRpcProviderService delegateRpcProviderService) {
         this.delegateRpcService = delegateRpcService;
         this.delegateRpcProviderService = delegateRpcProviderService;
+        this.delegateSchemaContextListener = null;
     }
 
     @Override
@@ -68,8 +76,7 @@ public final class DOMRpcRouter implements AutoCloseable, DOMRpcService, DOMRpcP
         org.opendaylight.mdsal.dom.api.DOMRpcImplementation delegateImpl =
             new org.opendaylight.mdsal.dom.api.DOMRpcImplementation() {
                 @Override
-                public CheckedFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult,
-                        org.opendaylight.mdsal.dom.api.DOMRpcException> invokeRpc(
+                public FluentFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult> invokeRpc(
                         org.opendaylight.mdsal.dom.api.DOMRpcIdentifier rpc, NormalizedNode<?, ?> input) {
                     return new MdsalDOMRpcResultFutureAdapter(implementation.invokeRpc(convert(rpc), input));
                 }
@@ -112,8 +119,8 @@ public final class DOMRpcRouter implements AutoCloseable, DOMRpcService, DOMRpcP
     @Override
     public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath type,
                                                                   final NormalizedNode<?, ?> input) {
-        final CheckedFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult, org.opendaylight.mdsal.dom.api.DOMRpcException>
-            future = delegateRpcService.invokeRpc(type, input);
+        final FluentFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult> future =
+                delegateRpcService.invokeRpc(type, input);
         return future instanceof MdsalDOMRpcResultFutureAdapter ? ((MdsalDOMRpcResultFutureAdapter)future).delegate()
                 : new LegacyDOMRpcResultFutureAdapter(future);
     }
@@ -159,8 +166,8 @@ public final class DOMRpcRouter implements AutoCloseable, DOMRpcService, DOMRpcP
     @Override
     @VisibleForTesting
     public void onGlobalContextUpdated(final SchemaContext context) {
-        if (delegateRpcService instanceof SchemaContextListener) {
-            ((SchemaContextListener)delegateRpcService).onGlobalContextUpdated(context);
+        if (delegateSchemaContextListener != null) {
+            delegateSchemaContextListener.onGlobalContextUpdated(context);
         }
     }
 }