Proxy MD-SAL interfaces in DOMMountPointServiceImpl
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / DOMRpcServiceAdapter.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.FluentFuture;
14 import java.util.Collection;
15 import java.util.Set;
16 import java.util.stream.Collectors;
17 import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
18 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
19 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
20 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
21 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
22 import org.opendaylight.yangtools.concepts.ListenerRegistration;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25
26 @Deprecated
27 public class DOMRpcServiceAdapter extends ForwardingObject implements org.opendaylight.mdsal.dom.api.DOMRpcService {
28     private final DOMRpcService delegate;
29
30     public DOMRpcServiceAdapter(final DOMRpcService delegate) {
31         this.delegate = requireNonNull(delegate);
32     }
33
34     @Override
35     public FluentFuture<DOMRpcResult> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
36         return new MdsalDOMRpcResultFutureAdapter(delegate().invokeRpc(type, input));
37     }
38
39     @Override
40     public <T extends org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener> ListenerRegistration<T>
41             registerRpcListener(final T listener) {
42         final ListenerRegistration<?> reg = delegate().registerRpcListener(new DOMRpcAvailabilityListener() {
43             @Override
44             public void onRpcAvailable(final Collection<DOMRpcIdentifier> rpcs) {
45                 listener.onRpcAvailable(convert(rpcs));
46             }
47
48             @Override
49             public void onRpcUnavailable(final Collection<DOMRpcIdentifier> rpcs) {
50                 listener.onRpcUnavailable(convert(rpcs));
51             }
52         });
53
54         return new AbstractListenerRegistration<T>(listener) {
55             @Override
56             protected void removeRegistration() {
57                 reg.close();
58             }
59         };
60     }
61
62     @Override
63     protected DOMRpcService delegate() {
64         return delegate;
65     }
66
67     public static Set<org.opendaylight.mdsal.dom.api.DOMRpcIdentifier> convert(
68             final Collection<DOMRpcIdentifier> rpcs) {
69         return rpcs.stream().map(DOMRpcIdentifier::toMdsal).collect(Collectors.toSet());
70     }
71 }

©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.