40ba2704f074dcc2cc77ddd6b09af7d65fc996a2
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / mdsal / AbstractDataListener.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.lispflowmapping.implementation.mdsal;
9
10 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
11 import org.opendaylight.mdsal.binding.api.DataBroker;
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;
17
18 /**
19  * The superclass for the different MD-SAL data change event listeners.
20  *
21  */
22 public abstract class AbstractDataListener<T extends DataObject> implements ClusteredDataTreeChangeListener<T> {
23     private DataBroker broker;
24     private InstanceIdentifier<T> path;
25     private ListenerRegistration<ClusteredDataTreeChangeListener<T>> configRegistration;
26     private ListenerRegistration<ClusteredDataTreeChangeListener<T>> operRegistration;
27
28     void registerDataChangeListener() {
29         final DataTreeIdentifier<T> configDataTreeIdentifier = DataTreeIdentifier.create(
30                 LogicalDatastoreType.CONFIGURATION, path);
31         final DataTreeIdentifier<T> operDataTreeIdentifier = DataTreeIdentifier.create(
32                 LogicalDatastoreType.OPERATIONAL, path);
33
34         configRegistration = broker.registerDataTreeChangeListener(configDataTreeIdentifier, this);
35         operRegistration = broker.registerDataTreeChangeListener(operDataTreeIdentifier, this);
36     }
37
38     public void closeDataChangeListener() {
39         configRegistration.close();
40         operRegistration.close();
41     }
42
43     void setBroker(DataBroker broker) {
44         this.broker = broker;
45     }
46
47     void setPath(InstanceIdentifier<T> path) {
48         this.path = path;
49     }
50
51 }