170d9c91750f80a71ad4b327f126ce0a745249c7
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / LegacyDOMRpcServiceAdapter.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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 static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ForwardingObject;
13 import com.google.common.util.concurrent.CheckedFuture;
14 import com.google.common.util.concurrent.FluentFuture;
15 import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
17 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
18 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
19 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
20 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23
24 @Deprecated
25 public class LegacyDOMRpcServiceAdapter extends ForwardingObject implements DOMRpcService {
26     private final org.opendaylight.mdsal.dom.api.DOMRpcService delegate;
27
28     public LegacyDOMRpcServiceAdapter(final org.opendaylight.mdsal.dom.api.DOMRpcService delegate) {
29         this.delegate = requireNonNull(delegate);
30     }
31
32     @Override
33     public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath type,
34                                                                   final NormalizedNode<?, ?> input) {
35         final FluentFuture<org.opendaylight.mdsal.dom.api.DOMRpcResult> future = delegate().invokeRpc(type, input);
36         return future instanceof MdsalDOMRpcResultFutureAdapter ? ((MdsalDOMRpcResultFutureAdapter)future).delegate()
37                 : new LegacyDOMRpcResultFutureAdapter(future);
38     }
39
40     @Override
41     public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T listener) {
42         final ListenerRegistration<org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener> reg =
43             delegate().registerRpcListener(new RpcAvailabilityListenerAdapter<>(listener));
44
45         return new AbstractListenerRegistration<T>(listener) {
46             @Override
47             protected void removeRegistration() {
48                 reg.close();
49             }
50         };
51     }
52
53     @Override
54     protected org.opendaylight.mdsal.dom.api.DOMRpcService delegate() {
55         return delegate;
56     }
57 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.