L2GW HwvtepHACache Utility class add in genius
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / datastoreutils / hwvtep / HwvtepClusteredDataTreeChangeListener.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.datastoreutils.hwvtep;
9
10 import java.util.concurrent.ExecutorService;
11 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
12 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
13 import org.opendaylight.mdsal.binding.api.DataBroker;
14 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
15 import org.opendaylight.serviceutils.tools.listener.AbstractClusteredAsyncDataTreeChangeListener;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18
19 public abstract class HwvtepClusteredDataTreeChangeListener<
20     T extends DataObject, K extends ClusteredDataTreeChangeListener<T>>
21         extends AbstractClusteredAsyncDataTreeChangeListener<T> {
22
23     private final HwvtepHACache hwvtepHACache;
24
25     public HwvtepClusteredDataTreeChangeListener(DataBroker dataBroker, DataTreeIdentifier dataTreeIdentifier,
26                                                  ExecutorService executorService, HwvtepHACache hwvtepHACache) {
27         super(dataBroker, dataTreeIdentifier, executorService);
28         this.hwvtepHACache = hwvtepHACache;
29     }
30
31     @Override
32     public void remove(InstanceIdentifier<T> identifier, T del) {
33         if (hwvtepHACache.isHAEnabledDevice(identifier)) {
34             return;
35         }
36         removed(identifier,del);
37     }
38
39     @Override
40     public void update(InstanceIdentifier<T> identifier, T original, T update) {
41         if (hwvtepHACache.isHAEnabledDevice(identifier)) {
42             return;
43         }
44         updated(identifier,original, update);
45     }
46
47     @Override
48     public void add(InstanceIdentifier<T> identifier, T add) {
49         if (hwvtepHACache.isHAEnabledDevice(identifier)) {
50             return;
51         }
52         added(identifier, add);
53     }
54
55     protected abstract void added(InstanceIdentifier<T> identifier, T add);
56
57     protected abstract void removed(InstanceIdentifier<T> identifier, T del);
58
59     protected abstract void updated(InstanceIdentifier<T> identifier, T original, T update);
60
61
62 }