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 org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
12 import org.opendaylight.genius.itm.globals.ITMConstants;
13 import org.opendaylight.genius.utils.cache.DataStoreCache;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelsState;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import javax.annotation.PostConstruct;
23 import javax.annotation.PreDestroy;
24 import javax.inject.Inject;
25 import javax.inject.Singleton;
28 public class StateTunnelListListener extends AsyncClusteredDataTreeChangeListenerBase<StateTunnelList,StateTunnelListListener> implements AutoCloseable{
29 private static final Logger LOG = LoggerFactory.getLogger(StateTunnelListListener.class);
30 private final DataBroker broker;
33 * Responsible for listening to tunnel interface state change
37 public StateTunnelListListener(final DataBroker dataBroker) {
38 super(StateTunnelList.class, StateTunnelListListener.class);
39 DataStoreCache.create(ITMConstants.TUNNEL_STATE_CACHE_NAME);
40 this.broker = dataBroker;
42 registerListener(LogicalDatastoreType.OPERATIONAL, this.broker);
43 } catch (final Exception e) {
44 LOG.error("StateTunnelListListener DataChange listener registration fail!", e);
49 public void start() throws Exception {
50 LOG.info("Tunnel Interface State Listener Started");
55 public void close() throws Exception {
56 LOG.info("Tunnel Interface State Listener Closed");
60 protected void remove(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList del) {
61 DataStoreCache.remove(ITMConstants.TUNNEL_STATE_CACHE_NAME, del.getTunnelInterfaceName());
65 protected void update(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList original,
66 StateTunnelList update) {
67 DataStoreCache.add(ITMConstants.TUNNEL_STATE_CACHE_NAME, update.getTunnelInterfaceName(), update);
71 protected void add(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList add) {
72 DataStoreCache.add(ITMConstants.TUNNEL_STATE_CACHE_NAME, add.getTunnelInterfaceName(), add);
76 protected StateTunnelListListener getDataTreeChangeListener() {
81 protected InstanceIdentifier<StateTunnelList> getWildCardPath() {
82 return InstanceIdentifier.builder(TunnelsState.class).
83 child(StateTunnelList.class).build();