7944eed88340a252b4b5a96eb814c309b9ed8f94
[netvirt.git] / statistics / impl / src / main / java / org / opendaylight / netvirt / statistics / CountersServiceInterfaceListener.java
1 /*
2  * Copyright (c) 2017 HPE, 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.netvirt.statistics;
9
10 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
14 import org.opendaylight.netvirt.statistics.api.ICountersInterfaceChangeHandler;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18
19 public class CountersServiceInterfaceListener
20         extends AsyncDataTreeChangeListenerBase<Interface, CountersServiceInterfaceListener>
21         implements ClusteredDataTreeChangeListener<Interface> {
22
23     private final ICountersInterfaceChangeHandler cich;
24     private final DataBroker db;
25
26     public CountersServiceInterfaceListener(final DataBroker db, final ICountersInterfaceChangeHandler cich) {
27         super(Interface.class, CountersServiceInterfaceListener.class);
28         this.db = db;
29         this.cich = cich;
30         registerListener(LogicalDatastoreType.CONFIGURATION, db);
31     }
32
33     @Override
34     protected InstanceIdentifier<Interface> getWildCardPath() {
35         return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
36     }
37
38     @Override
39     protected void remove(InstanceIdentifier<Interface> key, Interface port) {
40         cich.handleInterfaceRemoval(port.getName());
41     }
42
43     @Override
44     protected void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
45     }
46
47     @Override
48     protected void add(InstanceIdentifier<Interface> key, Interface port) {
49     }
50
51     @Override
52     protected CountersServiceInterfaceListener getDataTreeChangeListener() {
53         return this;
54     }
55
56 }