Bug 8153: Enforce check-style rules for netconf - sal-netconf-connector
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / SchemalessNetconfDeviceRpc.java
index d610904e6b76f2e34144d6c1a1f78a0c640e192b..4856e1178df76f2231f8a923c00ced57f68dfd28 100644 (file)
@@ -25,15 +25,12 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseRpcSchemalessTransformer;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.SchemalessMessageTransformer;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
-import org.opendaylight.netconf.sal.connect.util.MessageCounter;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Invokes RPC by sending netconf message via listener. Also transforms result from NetconfMessage to CompositeNode.
@@ -46,12 +43,13 @@ public final class SchemalessNetconfDeviceRpc implements DOMRpcService {
     private final RemoteDeviceId deviceId;
 
     public SchemalessNetconfDeviceRpc(final RemoteDeviceId deviceId,
-                                      final RemoteDeviceCommunicator<NetconfMessage> listener) {
+                                      final RemoteDeviceCommunicator<NetconfMessage> listener,
+                                      final BaseRpcSchemalessTransformer baseRpcTransformer,
+                                      final SchemalessMessageTransformer messageTransformer) {
         this.deviceId = deviceId;
         this.listener = listener;
-        final MessageCounter counter = new MessageCounter();
-        baseRpcTransformer = new BaseRpcSchemalessTransformer(counter);
-        schemalessTransformer = new SchemalessMessageTransformer(counter);
+        this.baseRpcTransformer = baseRpcTransformer;
+        this.schemalessTransformer = messageTransformer;
     }
 
     @Nonnull
@@ -64,45 +62,47 @@ public final class SchemalessNetconfDeviceRpc implements DOMRpcService {
         } else if (isBaseRpc(type)) {
             transformer = baseRpcTransformer;
         } else {
-            return Futures.immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("Unable to invoke rpc %s", type));
+            return Futures.immediateFailedCheckedFuture(
+                    new DOMRpcImplementationNotAvailableException("Unable to invoke rpc %s", type));
         }
         return handleRpc(type, input, transformer);
     }
 
-    private CheckedFuture<DOMRpcResult, DOMRpcException> handleRpc(@Nonnull final SchemaPath type,
-                                                                   @Nullable final NormalizedNode<?, ?> input,
-                                                                   final MessageTransformer<NetconfMessage> transformer) {
+    private CheckedFuture<DOMRpcResult, DOMRpcException> handleRpc(
+            @Nonnull final SchemaPath type, @Nullable final NormalizedNode<?, ?> input,
+            final MessageTransformer<NetconfMessage> transformer) {
         final NetconfMessage netconfMessage = transformer.toRpcRequest(type, input);
-        final ListenableFuture<RpcResult<NetconfMessage>> rpcResultListenableFuture = listener.sendRequest(netconfMessage, type.getLastComponent());
+        final ListenableFuture<RpcResult<NetconfMessage>> rpcResultListenableFuture =
+                listener.sendRequest(netconfMessage, type.getLastComponent());
 
-        final ListenableFuture<DOMRpcResult> transformed = Futures.transform(rpcResultListenableFuture, new Function<RpcResult<NetconfMessage>, DOMRpcResult>() {
-            @Override
-            public DOMRpcResult apply(final RpcResult<NetconfMessage> input) {
-                if (input.isSuccessful()) {
-                    return transformer.toRpcResult(input.getResult(), type);
+        final ListenableFuture<DOMRpcResult> transformed =
+            Futures.transform(rpcResultListenableFuture, (Function<RpcResult<NetconfMessage>, DOMRpcResult>) input1 -> {
+                if (input1.isSuccessful()) {
+                    return transformer.toRpcResult(input1.getResult(), type);
                 } else {
-                    return new DefaultDOMRpcResult(input.getErrors());
+                    return new DefaultDOMRpcResult(input1.getErrors());
                 }
-            }
-        });
+            });
 
         return Futures.makeChecked(transformed, new Function<Exception, DOMRpcException>() {
             @Nullable
             @Override
-            public DOMRpcException apply(@Nullable final Exception e) {
-                return new DOMRpcImplementationNotAvailableException(e, "Unable to invoke rpc %s on device %s", type, deviceId);
+            public DOMRpcException apply(@Nullable final Exception exception) {
+                return new DOMRpcImplementationNotAvailableException(
+                        exception, "Unable to invoke rpc %s on device %s", type, deviceId);
             }
         });
     }
 
 
-    private boolean isBaseRpc(final SchemaPath type) {
+    private static boolean isBaseRpc(final SchemaPath type) {
         return NetconfMessageTransformUtil.NETCONF_URI.equals(type.getLastComponent().getNamespace());
     }
 
     @Nonnull
     @Override
-    public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(@Nonnull final T listener) {
+    public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(
+            @Nonnull final T listener) {
         throw new UnsupportedOperationException("Not available for netconf 1.0");
     }