Adjust to mdsal invokeRpc API change 66/74366/5
authorTom Pantelis <tompantelis@gmail.com>
Tue, 24 Jul 2018 00:07:26 +0000 (20:07 -0400)
committerRobert Varga <nite@hq.sk>
Tue, 24 Jul 2018 17:05:01 +0000 (17:05 +0000)
mdsal patch: https://git.opendaylight.org/gerrit/#/c/74365/

Change-Id: Ie14d9d582f5e6f141b852248f2b7cc8dca1b97b3
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ActionProviderBean.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/RpcServiceAdapter.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMRpcRouter.java
opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMRpcRouterTest.java
opendaylight/md-sal/sal-dom-compat/src/main/java/org/opendaylight/controller/sal/core/compat/AbstractDOMRpcResultFutureAdapter.java
opendaylight/md-sal/sal-dom-compat/src/main/java/org/opendaylight/controller/sal/core/compat/LegacyDOMRpcResultFutureAdapter.java
opendaylight/md-sal/sal-dom-compat/src/main/java/org/opendaylight/controller/sal/core/compat/MdsalDOMRpcResultFutureAdapter.java

index 1a0c712..70054f8 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.controller.blueprint.ext;
 
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.Futures;
 import java.util.Collection;
 import java.util.Set;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
@@ -19,6 +18,7 @@ import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.RpcRoutingStrategy;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.osgi.framework.Bundle;
@@ -130,7 +130,7 @@ public class ActionProviderBean {
 
         final Set<DOMRpcIdentifier> rpcs = ImmutableSet.copyOf(Collections2.transform(paths, DOMRpcIdentifier::create));
         reg = domRpcProvider.registerRpcImplementation((rpc, input) -> {
-            return Futures.immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException(
+            return FluentFutures.immediateFailedFluentFuture(new DOMRpcImplementationNotAvailableException(
                 "Action %s has no instance matching %s", rpc, input));
         }, rpcs);
         LOG.debug("Registered provider for {}", interfaceName);
index daf502c..63c20e5 100644 (file)
@@ -18,6 +18,7 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Collection;
 import java.util.Map.Entry;
+import java.util.concurrent.Future;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
@@ -70,8 +71,8 @@ class RpcServiceAdapter implements InvocationHandler {
         if (result instanceof BindingRpcFutureAware) {
             return ((BindingRpcFutureAware) result).getBindingFuture();
         } else if (result instanceof LegacyDOMRpcResultFutureAdapter) {
-            CheckedFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult, org.opendaylight.mdsal.dom.api.DOMRpcException>
-                    delegateFuture = ((LegacyDOMRpcResultFutureAdapter)result).delegate();
+            Future<org.opendaylight.mdsal.dom.api.DOMRpcResult> delegateFuture =
+                    ((LegacyDOMRpcResultFutureAdapter)result).delegate();
             if (delegateFuture instanceof BindingRpcFutureAware) {
                 return ((BindingRpcFutureAware) delegateFuture).getBindingFuture();
             }
index 6446cbd..d78e9b9 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;
@@ -75,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));
                 }
@@ -119,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);
     }
index 4f555fb..259cbfb 100644 (file)
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.verify;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.AbstractMap.SimpleEntry;
@@ -43,6 +44,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.store.impl.TestModel;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -190,7 +192,7 @@ public class DOMRpcRouterTest {
         org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult result =
             new org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult(RPC_OUTPUT,
                 Collections.singleton(RpcResultBuilder.newError(ErrorType.RPC, "tag", "message")));
-        testMdsalRpcImpl.init(Futures.immediateCheckedFuture(result));
+        testMdsalRpcImpl.init(FluentFutures.immediateFluentFuture(result));
 
         ListenableFuture<DOMRpcResult> future = legacyRpcRouter.invokeRpc(legacyTestRpcIdentifier.getType(), RPC_INPUT);
 
@@ -204,7 +206,7 @@ public class DOMRpcRouterTest {
         // Test exception returned
 
         TestMdsalDOMRpcException rpcEx = new TestMdsalDOMRpcException();
-        testMdsalRpcImpl.init(Futures.immediateFailedCheckedFuture(rpcEx));
+        testMdsalRpcImpl.init(FluentFutures.immediateFailedFluentFuture(rpcEx));
 
         try {
             legacyRpcRouter.invokeRpc(legacyTestRpcIdentifier.getType(), RPC_INPUT).get();
@@ -216,7 +218,7 @@ public class DOMRpcRouterTest {
 
         // Test no input or output
 
-        testMdsalRpcImpl.init(Futures.immediateCheckedFuture(null));
+        testMdsalRpcImpl.init(FluentFutures.immediateNullFluentFuture());
 
         future = legacyRpcRouter.invokeRpc(legacyTestRpcNoInputIdentifier.getType(), null);
 
@@ -318,19 +320,16 @@ public class DOMRpcRouterTest {
     private static class TestMdsalDOMRpcImplementation
             extends AbstractDOMRpcImplementation<org.opendaylight.mdsal.dom.api.DOMRpcIdentifier>
             implements org.opendaylight.mdsal.dom.api.DOMRpcImplementation {
-        CheckedFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult,
-                org.opendaylight.mdsal.dom.api.DOMRpcException> returnFuture;
+        FluentFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult> returnFuture;
 
         @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(
                     final org.opendaylight.mdsal.dom.api.DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
             rpcInput = new SimpleEntry<>(rpc, input);
             return returnFuture;
         }
 
-        void init(CheckedFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult,
-                org.opendaylight.mdsal.dom.api.DOMRpcException> retFuture) {
+        void init(FluentFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult> retFuture) {
             this.returnFuture = retFuture;
             rpcInput = null;
         }
index 376682a..a16e4fa 100644 (file)
@@ -7,8 +7,8 @@
  */
 package org.opendaylight.controller.sal.core.compat;
 
-import com.google.common.util.concurrent.CheckedFuture;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import com.google.common.util.concurrent.AbstractFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executor;
@@ -24,20 +24,20 @@ import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
  * @author Thomas Pantelis
  */
 @SuppressWarnings("checkstyle:ClassTypeParameterName")
-public abstract class AbstractDOMRpcResultFutureAdapter<T extends DOMRpcResult, TE extends DOMRpcException,
-        F extends DOMRpcResult, FE extends DOMRpcException> implements CheckedFuture<T, TE> {
-    private final CheckedFuture<F, FE> delegate;
-    private final ExceptionMapper<TE> exMapper;
+public abstract class AbstractDOMRpcResultFutureAdapter<T extends DOMRpcResult, F extends DOMRpcResult,
+        D extends ListenableFuture<F>, E extends DOMRpcException> extends AbstractFuture<T> {
+    private final D delegate;
+    private final ExceptionMapper<E> exMapper;
     private volatile Optional<T> result;
 
-    AbstractDOMRpcResultFutureAdapter(CheckedFuture<F, FE> delegate, ExceptionMapper<TE> exMapper) {
+    AbstractDOMRpcResultFutureAdapter(D delegate, ExceptionMapper<E> exMapper) {
         this.delegate = delegate;
         this.exMapper = exMapper;
     }
 
     protected abstract T transform(F fromResult);
 
-    public CheckedFuture<F, FE> delegate() {
+    public D delegate() {
         return delegate;
     }
 
@@ -88,26 +88,6 @@ public abstract class AbstractDOMRpcResultFutureAdapter<T extends DOMRpcResult,
         }
     }
 
-    @Override
-    @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
-    public T checkedGet() throws TE {
-        try {
-            return get();
-        } catch (InterruptedException | ExecutionException e) {
-            throw exMapper.apply(e);
-        }
-    }
-
-    @Override
-    @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
-    public T checkedGet(final long timeout, final TimeUnit unit) throws TimeoutException, TE {
-        try {
-            return get(timeout, unit);
-        } catch (InterruptedException | ExecutionException e) {
-            throw exMapper.apply(e);
-        }
-    }
-
     private synchronized T transformIfNecessary(F delegateResult) {
         if (result == null) {
             if (delegateResult == null) {
index 3e80344..10a85fe 100644 (file)
@@ -8,6 +8,11 @@
 package org.opendaylight.controller.sal.core.compat;
 
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
@@ -20,8 +25,9 @@ import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
  *
  * @author Thomas Pantelis
  */
-public class LegacyDOMRpcResultFutureAdapter extends AbstractDOMRpcResultFutureAdapter<DOMRpcResult, DOMRpcException,
-        org.opendaylight.mdsal.dom.api.DOMRpcResult, org.opendaylight.mdsal.dom.api.DOMRpcException> {
+public class LegacyDOMRpcResultFutureAdapter extends AbstractDOMRpcResultFutureAdapter<DOMRpcResult,
+        org.opendaylight.mdsal.dom.api.DOMRpcResult, FluentFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult>,
+        DOMRpcException> implements CheckedFuture<DOMRpcResult, DOMRpcException> {
 
     private static final ExceptionMapper<DOMRpcException> LEGACY_DOM_RPC_EX_MAPPER =
             new ExceptionMapper<DOMRpcException>("rpc", DOMRpcException.class) {
@@ -34,11 +40,30 @@ public class LegacyDOMRpcResultFutureAdapter extends AbstractDOMRpcResultFutureA
         }
     };
 
-    public LegacyDOMRpcResultFutureAdapter(CheckedFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult,
-            org.opendaylight.mdsal.dom.api.DOMRpcException> delegate) {
+    public LegacyDOMRpcResultFutureAdapter(FluentFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult> delegate) {
         super(delegate, LEGACY_DOM_RPC_EX_MAPPER);
     }
 
+    @Override
+    @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
+    public DOMRpcResult checkedGet() throws DOMRpcException {
+        try {
+            return get();
+        } catch (InterruptedException | ExecutionException e) {
+            throw LEGACY_DOM_RPC_EX_MAPPER.apply(e);
+        }
+    }
+
+    @Override
+    @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
+    public DOMRpcResult checkedGet(final long timeout, final TimeUnit unit) throws TimeoutException, DOMRpcException {
+        try {
+            return get(timeout, unit);
+        } catch (InterruptedException | ExecutionException e) {
+            throw LEGACY_DOM_RPC_EX_MAPPER.apply(e);
+        }
+    }
+
     @Override
     protected DOMRpcResult transform(org.opendaylight.mdsal.dom.api.DOMRpcResult fromResult) {
         return new DefaultDOMRpcResult(fromResult.getResult(), fromResult.getErrors());
index bc06110..acd341b 100644 (file)
@@ -21,8 +21,9 @@ import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
  * @author Thomas Pantelis
  */
 public class MdsalDOMRpcResultFutureAdapter extends AbstractDOMRpcResultFutureAdapter<
-        DOMRpcResult, DOMRpcException, org.opendaylight.controller.md.sal.dom.api.DOMRpcResult,
-            org.opendaylight.controller.md.sal.dom.api.DOMRpcException> {
+        DOMRpcResult, org.opendaylight.controller.md.sal.dom.api.DOMRpcResult,
+        CheckedFuture<org.opendaylight.controller.md.sal.dom.api.DOMRpcResult,
+            org.opendaylight.controller.md.sal.dom.api.DOMRpcException>, DOMRpcException> {
     private static final ExceptionMapper<DOMRpcException> MDSAL_DOM_RPC_EX_MAPPER =
             new ExceptionMapper<DOMRpcException>("rpc", DOMRpcException.class) {
         @Override

©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.