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 javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
private final SchemalessMessageTransformer schemalessTransformer;
private final RemoteDeviceId deviceId;
- public SchemalessNetconfDeviceRpc(RemoteDeviceId deviceId, final RemoteDeviceCommunicator<NetconfMessage> listener,
+ public SchemalessNetconfDeviceRpc(final RemoteDeviceId deviceId,
+ final RemoteDeviceCommunicator<NetconfMessage> listener,
final BaseRpcSchemalessTransformer baseRpcTransformer,
final SchemalessMessageTransformer messageTransformer) {
this.deviceId = deviceId;
} 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());
}
- }
- });
+ }, MoreExecutors.directExecutor());
- 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);
- }
- });
+ return Futures.makeChecked(transformed,
+ e -> new DOMRpcImplementationNotAvailableException(e,
+ "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 lsnr) {
throw new UnsupportedOperationException("Not available for netconf 1.0");
}