Bump upstreams
[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.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.Registration;
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 DataTreeChangeListener<T> {
23     private DataBroker broker;
24     private InstanceIdentifier<T> path;
25     private Registration configRegistration;
26     private Registration operRegistration;
27
28     void registerDataChangeListener() {
29         configRegistration = broker.registerTreeChangeListener(
30             DataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, path), this);
31         operRegistration = broker.registerTreeChangeListener(
32             DataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL, path), this);
33     }
34
35     public void closeDataChangeListener() {
36         configRegistration.close();
37         operRegistration.close();
38     }
39
40     void setBroker(DataBroker broker) {
41         this.broker = broker;
42     }
43
44     void setPath(InstanceIdentifier<T> path) {
45         this.path = path;
46     }
47 }