Clean up mdsal-netconf-notification
[netconf.git] / netconf / mdsal-netconf-notification / src / main / java / org / opendaylight / netconf / mdsal / notification / impl / OperationalDatastoreListener.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.netconf.mdsal.notification.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
14 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.yangtools.concepts.ListenerRegistration;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19
20 /**
21  * Abstract base class for subclasses, which want to listen for changes on specified subtree in operational datastore.
22  *
23  * @param <T> data object class
24  */
25 abstract class OperationalDatastoreListener<T extends DataObject> implements DataTreeChangeListener<T> {
26     private final InstanceIdentifier<T> instanceIdentifier;
27
28     /**
29      * Constructor.
30      *
31      * @param instanceIdentifier instance identifier of subtree, on which this instance should listen on changes.
32      */
33     OperationalDatastoreListener(final InstanceIdentifier<T> instanceIdentifier) {
34         this.instanceIdentifier = requireNonNull(instanceIdentifier);
35     }
36
37     /**
38      * Registers this instance as OPERATIONAL datastore listener via provided dataBroker.
39      *
40      * @param dataBroker data broker
41      * @return listener registration
42      */
43     ListenerRegistration<OperationalDatastoreListener<T>> registerOnChanges(final DataBroker dataBroker) {
44         DataTreeIdentifier<T> id = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
45         return dataBroker.registerDataTreeChangeListener(id, this);
46     }
47
48 }