2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.genius.itm.listeners.cache;
11 import javax.annotation.PostConstruct;
12 import javax.annotation.PreDestroy;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
18 import org.opendaylight.genius.itm.globals.ITMConstants;
19 import org.opendaylight.genius.utils.cache.DataStoreCache;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelsState;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 public class StateTunnelListListener extends AsyncClusteredDataTreeChangeListenerBase<StateTunnelList,StateTunnelListListener> implements AutoCloseable{
28 private static final Logger LOG = LoggerFactory.getLogger(StateTunnelListListener.class);
29 private final DataBroker broker;
32 * Responsible for listening to tunnel interface state change
36 public StateTunnelListListener(final DataBroker dataBroker) {
37 super(StateTunnelList.class, StateTunnelListListener.class);
38 DataStoreCache.create(ITMConstants.TUNNEL_STATE_CACHE_NAME);
39 this.broker = dataBroker;
41 registerListener(LogicalDatastoreType.OPERATIONAL, this.broker);
42 } catch (final Exception e) {
43 LOG.error("StateTunnelListListener DataChange listener registration fail!", e);
48 public void start() throws Exception {
49 LOG.info("Tunnel Interface State Listener Started");
54 public void close() throws Exception {
55 LOG.info("Tunnel Interface State Listener Closed");
59 protected void remove(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList del) {
60 DataStoreCache.remove(ITMConstants.TUNNEL_STATE_CACHE_NAME, del.getTunnelInterfaceName());
64 protected void update(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList original,
65 StateTunnelList update) {
66 DataStoreCache.add(ITMConstants.TUNNEL_STATE_CACHE_NAME, update.getTunnelInterfaceName(), update);
70 protected void add(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList add) {
71 DataStoreCache.add(ITMConstants.TUNNEL_STATE_CACHE_NAME, add.getTunnelInterfaceName(), add);
75 protected StateTunnelListListener getDataTreeChangeListener() {
80 protected InstanceIdentifier<StateTunnelList> getWildCardPath() {
81 return InstanceIdentifier.builder(TunnelsState.class).
82 child(StateTunnelList.class).build();