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 org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
12 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
13 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
14 import org.opendaylight.controller.md.sal.dom.api.DefaultDOMRpcException;
15 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
16 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
19 * Adapts a {@link org.opendaylight.mdsal.dom.api.DOMRpcResult} CheckedFuture to a {@link DOMRpcResult} CheckedFuture.
21 * @author Thomas Pantelis
23 public class LegacyDOMRpcResultFutureAdapter extends AbstractDOMRpcResultFutureAdapter<DOMRpcResult, DOMRpcException,
24 org.opendaylight.mdsal.dom.api.DOMRpcResult, org.opendaylight.mdsal.dom.api.DOMRpcException> {
26 private static final ExceptionMapper<DOMRpcException> LEGACY_DOM_RPC_EX_MAPPER =
27 new ExceptionMapper<DOMRpcException>("rpc", DOMRpcException.class) {
29 protected DOMRpcException newWithCause(String message, Throwable cause) {
30 return cause instanceof DOMRpcException ? (DOMRpcException)cause
31 : cause instanceof org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException
32 ? new DOMRpcImplementationNotAvailableException(cause.getMessage(), cause.getCause())
33 : new DefaultDOMRpcException("RPC failed", cause);
37 public LegacyDOMRpcResultFutureAdapter(CheckedFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult,
38 org.opendaylight.mdsal.dom.api.DOMRpcException> delegate) {
39 super(delegate, LEGACY_DOM_RPC_EX_MAPPER);
43 protected DOMRpcResult transform(org.opendaylight.mdsal.dom.api.DOMRpcResult fromResult) {
44 return new DefaultDOMRpcResult(fromResult.getResult(), fromResult.getErrors());