Import MappingCheckedFuture from mdsal
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / RpcServiceAdapter.java
index 7f2a074af23db07a928a773a6f8e7ec1af2bb8fb..c6ea9db3d861967003be34a1c6f92d13ecc2801c 100644 (file)
@@ -1,10 +1,11 @@
 /*
  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
  *
- * This program and the accompanying materials are made available under the terms of the Eclipse
- * Public License v1.0 which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.controller.md.sal.binding.impl;
 
 import com.google.common.base.Function;
@@ -21,7 +22,7 @@ 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;
 import org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy;
-import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -60,8 +61,12 @@ class RpcServiceAdapter implements InvocationHandler {
         proxy = (RpcService) Proxy.newProxyInstance(type.getClassLoader(), new Class[] {type}, this);
     }
 
-    private final ListenableFuture<RpcResult<?>> invoke0(final SchemaPath schemaPath, final NormalizedNode<?, ?> input) {
+    private ListenableFuture<RpcResult<?>> invoke0(final SchemaPath schemaPath, final NormalizedNode<?, ?> input) {
         final CheckedFuture<DOMRpcResult, DOMRpcException> result = delegate.invokeRpc(schemaPath, input);
+        if(result instanceof LazyDOMRpcResultFuture) {
+            return ((LazyDOMRpcResultFuture) result).getBindingFuture();
+        }
+
         return transformFuture(schemaPath, result, codec.getCodecFactory());
     }
 
@@ -100,14 +105,15 @@ class RpcServiceAdapter implements InvocationHandler {
     private static boolean isObjectMethod(final Method m) {
         switch (m.getName()) {
             case "toString":
-                return (m.getReturnType() == String.class && m.getParameterTypes().length == 0);
+                return (m.getReturnType().equals(String.class) && m.getParameterTypes().length == 0);
             case "hashCode":
-                return (m.getReturnType() == int.class && m.getParameterTypes().length == 0);
+                return (m.getReturnType().equals(int.class) && m.getParameterTypes().length == 0);
             case "equals":
-                return (m.getReturnType() == boolean.class && m.getParameterTypes().length == 1 && m
+                return (m.getReturnType().equals(boolean.class) && m.getParameterTypes().length == 1 && m
                         .getParameterTypes()[0] == Object.class);
+            default:
+                return false;
         }
-        return false;
     }
 
     private Object callObjectMethod(final Object self, final Method m, final Object[] args) {
@@ -118,28 +124,23 @@ class RpcServiceAdapter implements InvocationHandler {
                 return System.identityHashCode(self);
             case "equals":
                 return (self == args[0]);
+            default:
+                return null;
         }
-        return null;
     }
 
     private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,
-            final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeCodecRegistry codec) {
-        return Futures.transform(domFuture, new Function<DOMRpcResult, RpcResult<?>>() {
-            @Override
-            public RpcResult<?> apply(final DOMRpcResult input) {
-                if (input instanceof LazySerializedDOMRpcResult) {
-                    return ((LazySerializedDOMRpcResult) input).bidningRpcResult();
-                }
-                final NormalizedNode<?, ?> domData = input.getResult();
-                final DataObject bindingResult;
-                if (domData != null) {
-                    final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
-                    bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
-                } else {
-                    bindingResult = null;
-                }
-                return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
+            final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
+        return Futures.transform(domFuture, (Function<DOMRpcResult, RpcResult<?>>) input -> {
+            final NormalizedNode<?, ?> domData = input.getResult();
+            final DataObject bindingResult;
+            if (domData != null) {
+                final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
+                bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
+            } else {
+                bindingResult = null;
             }
+            return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
         });
     }