Adjust to mdsal invokeRpc API change
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / LegacyDOMRpcResultFutureAdapter.java
index 3e803449bdf4ddba704695b8cd3539cc1b413212..10a85feba27c5cf1c2cb71eab64b97684bedbaa7 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());