Proxy MD-SAL interfaces in DOMMountPointServiceImpl
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / MdsalDOMRpcResultFutureAdapter.java
1 /*
2  * Copyright (c) 2018 Inocybe Technologies and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.core.compat;
9
10 import com.google.common.util.concurrent.CheckedFuture;
11 import org.opendaylight.mdsal.dom.api.DOMRpcException;
12 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
13 import org.opendaylight.mdsal.dom.api.DefaultDOMRpcException;
14 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
15 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
16
17 /**
18  * Adapts a {@link org.opendaylight.controller.md.sal.dom.api.DOMRpcResult} CheckedFuture to a
19  * {@link DOMRpcResult} CheckedFuture.
20  *
21  * @author Thomas Pantelis
22  */
23 public class MdsalDOMRpcResultFutureAdapter extends AbstractDOMRpcResultFutureAdapter<
24         DOMRpcResult, org.opendaylight.controller.md.sal.dom.api.DOMRpcResult,
25         CheckedFuture<org.opendaylight.controller.md.sal.dom.api.DOMRpcResult,
26             org.opendaylight.controller.md.sal.dom.api.DOMRpcException>, DOMRpcException> {
27     private static final ExceptionMapper<DOMRpcException> MDSAL_DOM_RPC_EX_MAPPER =
28             new ExceptionMapper<DOMRpcException>("rpc", DOMRpcException.class) {
29         @Override
30         protected DOMRpcException newWithCause(String message, Throwable cause) {
31             return cause instanceof DOMRpcException ? (DOMRpcException) cause
32                     : new DefaultDOMRpcException("RPC failed", cause);
33         }
34     };
35
36     public MdsalDOMRpcResultFutureAdapter(CheckedFuture<org.opendaylight.controller.md.sal.dom.api.DOMRpcResult,
37             org.opendaylight.controller.md.sal.dom.api.DOMRpcException> delegate) {
38         super(delegate, MDSAL_DOM_RPC_EX_MAPPER);
39     }
40
41     @Override
42     protected DOMRpcResult transform(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult fromResult) {
43         return new DefaultDOMRpcResult(fromResult.getResult(), fromResult.getErrors());
44     }
45 }