*/
package org.opendaylight.netconf.sal.connect.netconf.sal;
-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.FluentFuture;
+import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.MoreExecutors;
+import com.google.common.util.concurrent.SettableFuture;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
-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;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
+import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
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;
this.schemalessTransformer = messageTransformer;
}
- @Nonnull
@Override
- public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final SchemaPath type,
- @Nullable final NormalizedNode<?, ?> input) {
+ public FluentFuture<DOMRpcResult> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
final MessageTransformer<NetconfMessage> transformer;
if (input instanceof AnyXmlNode) {
transformer = schemalessTransformer;
} else if (isBaseRpc(type)) {
transformer = baseRpcTransformer;
} else {
- return Futures.immediateFailedCheckedFuture(
- new DOMRpcImplementationNotAvailableException("Unable to invoke rpc %s", type));
+ return FluentFutures.immediateFailedFluentFuture(new DOMRpcImplementationNotAvailableException(
+ "Unable to invoke rpc %s", type));
}
return handleRpc(type, input, transformer);
}
- private CheckedFuture<DOMRpcResult, DOMRpcException> handleRpc(
+ private FluentFuture<DOMRpcResult> 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 FluentFuture<RpcResult<NetconfMessage>> delegateFuture = listener.sendRequest(
+ transformer.toRpcRequest(type, input), type.getLastComponent());
- final ListenableFuture<DOMRpcResult> transformed =
- Futures.transform(rpcResultListenableFuture, input1 -> {
- if (input1.isSuccessful()) {
- return transformer.toRpcResult(input1.getResult(), type);
- }
+ final SettableFuture<DOMRpcResult> ret = SettableFuture.create();
+ delegateFuture.addCallback(new FutureCallback<RpcResult<NetconfMessage>>() {
+ @Override
+ public void onSuccess(RpcResult<NetconfMessage> result) {
+ ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type)
+ : new DefaultDOMRpcResult(result.getErrors()));
+ }
- return new DefaultDOMRpcResult(input1.getErrors());
- }, MoreExecutors.directExecutor());
+ @Override
+ public void onFailure(Throwable cause) {
+ ret.setException(new DOMRpcImplementationNotAvailableException(cause,
+ "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));
+ }, MoreExecutors.directExecutor());
+ return ret;
}
private static boolean isBaseRpc(final SchemaPath type) {