X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2Fsal%2FNetconfDeviceRpc.java;h=897cdaa5c73267039b1438aed9054cb69c37b9d9;hb=e1352a34274092cde87343386655fe984e45df0e;hp=d1282d09b45c58c82785e391a11059705c2c25da;hpb=e7a21c13dc252a17a1dab0a6b8087de128a845b6;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceRpc.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceRpc.java index d1282d09b4..897cdaa5c7 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceRpc.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceRpc.java @@ -7,11 +7,11 @@ */ package org.opendaylight.netconf.sal.connect.netconf.sal; -import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; import java.util.Collection; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -28,7 +28,6 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; @@ -37,55 +36,45 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; */ public final class NetconfDeviceRpc implements DOMRpcService { - private static final Function RPC_TO_RPC_IDENTIFIER = new Function() { - @Override - public DOMRpcIdentifier apply(final RpcDefinition input) { - return DOMRpcIdentifier.create(input.getPath()); - } - }; - - private final RemoteDeviceCommunicator listener; + private final RemoteDeviceCommunicator communicator; private final MessageTransformer transformer; private final Collection availableRpcs; - public NetconfDeviceRpc(final SchemaContext schemaContext, final RemoteDeviceCommunicator listener, final MessageTransformer transformer) { - this.listener = listener; + public NetconfDeviceRpc(final SchemaContext schemaContext, + final RemoteDeviceCommunicator communicator, + final MessageTransformer transformer) { + this.communicator = communicator; this.transformer = transformer; - availableRpcs = Collections2.transform(schemaContext.getOperations(), RPC_TO_RPC_IDENTIFIER); + availableRpcs = Collections2.transform(schemaContext.getOperations(), + input -> DOMRpcIdentifier.create(input.getPath())); } @Nonnull @Override - public CheckedFuture invokeRpc(@Nonnull final SchemaPath type, @Nullable final NormalizedNode input) { + public CheckedFuture invokeRpc(@Nonnull final SchemaPath type, + @Nullable final NormalizedNode input) { final NetconfMessage message = transformer.toRpcRequest(type, input); - final ListenableFuture> delegateFutureWithPureResult = listener.sendRequest(message, type.getLastComponent()); + final ListenableFuture> delegateFutureWithPureResult = + communicator.sendRequest(message, type.getLastComponent()); - final ListenableFuture transformed = Futures.transform(delegateFutureWithPureResult, new Function, DOMRpcResult>() { - @Override - public DOMRpcResult apply(final RpcResult input) { - if (input.isSuccessful()) { - return transformer.toRpcResult(input.getResult(), type); + final ListenableFuture transformed = + Futures.transform(delegateFutureWithPureResult, input1 -> { + if (input1.isSuccessful()) { + return transformer.toRpcResult(input1.getResult(), type); } else { - // TODO check whether the listener sets errors properly - return new DefaultDOMRpcResult(input.getErrors()); + return new DefaultDOMRpcResult(input1.getErrors()); } - } - }); + }, MoreExecutors.directExecutor()); - return Futures.makeChecked(transformed, new Function() { - @Nullable - @Override - public DOMRpcException apply(@Nullable final Exception e) { - // FIXME what other possible exceptions are there ? - return new DOMRpcImplementationNotAvailableException(e, "Unable to invoke rpc %s", type); - } - }); + return Futures.makeChecked(transformed, exception -> + new DOMRpcImplementationNotAvailableException(exception, "Unable to invoke rpc %s", type)); } @Nonnull @Override - public ListenerRegistration registerRpcListener(@Nonnull final T listener) { + public ListenerRegistration registerRpcListener( + @Nonnull final T listener) { listener.onRpcAvailable(availableRpcs);