Proxy MD-SAL interfaces in DOMMountPointServiceImpl
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / DOMDataTreeChangeServiceAdapter.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 org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
17 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19
20 @Deprecated
21 public class DOMDataTreeChangeServiceAdapter extends ForwardingObject
22         implements org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService {
23
24     private final DOMDataTreeChangeService delegate;
25
26     DOMDataTreeChangeServiceAdapter(final DOMDataTreeChangeService delegate) {
27         this.delegate = requireNonNull(delegate);
28     }
29
30     @Override
31     public <L extends org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> ListenerRegistration<L>
32             registerDataTreeChangeListener(final org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier treeId,
33                     final L listener) {
34         final DOMDataTreeChangeListener delegateListener;
35         if (listener instanceof org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) {
36             delegateListener = (ClusteredDOMDataTreeChangeListener) listener::onDataTreeChanged;
37         } else {
38             delegateListener = listener::onDataTreeChanged;
39         }
40         final ListenerRegistration<?> reg = delegate().registerDataTreeChangeListener(
41             DOMDataTreeIdentifier.fromMdsal(treeId), delegateListener);
42
43         return new AbstractListenerRegistration<L>(listener) {
44             @Override
45             protected void removeRegistration() {
46                 reg.close();
47             }
48         };
49     }
50
51     @Override
52     protected DOMDataTreeChangeService delegate() {
53         return delegate;
54     }
55 }

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