2 * Copyright (c) 2018 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.core.compat;
10 import com.google.common.util.concurrent.CheckedFuture;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.util.concurrent.ExecutionException;
14 import java.util.concurrent.TimeUnit;
15 import java.util.concurrent.TimeoutException;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
17 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
18 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
19 import org.opendaylight.controller.md.sal.dom.api.DefaultDOMRpcException;
20 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
21 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
24 * Adapts a {@link org.opendaylight.mdsal.dom.api.DOMRpcResult} CheckedFuture to a {@link DOMRpcResult} CheckedFuture.
26 * @author Thomas Pantelis
29 public class LegacyDOMRpcResultFutureAdapter extends AbstractDOMRpcResultFutureAdapter<DOMRpcResult,
30 org.opendaylight.mdsal.dom.api.DOMRpcResult, ListenableFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult>,
31 DOMRpcException> implements CheckedFuture<DOMRpcResult, DOMRpcException> {
33 private static final ExceptionMapper<DOMRpcException> LEGACY_DOM_RPC_EX_MAPPER =
34 new ExceptionMapper<DOMRpcException>("rpc", DOMRpcException.class) {
36 protected DOMRpcException newWithCause(String message, Throwable cause) {
37 return cause instanceof DOMRpcException ? (DOMRpcException)cause
38 : cause instanceof org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException
39 ? new DOMRpcImplementationNotAvailableException(cause.getMessage(), cause.getCause())
40 : new DefaultDOMRpcException("RPC failed", cause);
44 public LegacyDOMRpcResultFutureAdapter(ListenableFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult> delegate) {
45 super(delegate, LEGACY_DOM_RPC_EX_MAPPER);
49 @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
50 public DOMRpcResult checkedGet() throws DOMRpcException {
53 } catch (InterruptedException | ExecutionException e) {
54 throw LEGACY_DOM_RPC_EX_MAPPER.apply(e);
59 @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
60 public DOMRpcResult checkedGet(final long timeout, final TimeUnit unit) throws TimeoutException, DOMRpcException {
62 return get(timeout, unit);
63 } catch (InterruptedException | ExecutionException e) {
64 throw LEGACY_DOM_RPC_EX_MAPPER.apply(e);
69 protected DOMRpcResult transform(org.opendaylight.mdsal.dom.api.DOMRpcResult fromResult) {
70 return new DefaultDOMRpcResult(fromResult.getResult(), fromResult.getErrors());