2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.mdsal.notification.impl;
10 import org.opendaylight.mdsal.binding.api.DataBroker;
11 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
12 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 * Abstract base class for subclasses, which want to listen for changes on specified subtree in operational datastore.
21 * @param <T> data object class
23 abstract class OperationalDatastoreListener<T extends DataObject> implements DataTreeChangeListener<T> {
25 private final InstanceIdentifier<T> instanceIdentifier;
30 * @param instanceIdentifier instance identifier of subtree, on which this instance should listen on changes.
32 OperationalDatastoreListener(final InstanceIdentifier<T> instanceIdentifier) {
33 this.instanceIdentifier = instanceIdentifier;
37 * Registers this instance as OPERATIONAL datastore listener via provided dataBroker.
39 * @param dataBroker data broker
40 * @return listener registration
42 ListenerRegistration<OperationalDatastoreListener<T>> registerOnChanges(final DataBroker dataBroker) {
43 DataTreeIdentifier<T> id = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
44 return dataBroker.registerDataTreeChangeListener(id, this);