ITM impl Organize Imports for Checkstyle compliance
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / listeners / cache / ItmMonitoringListener.java
1 /*
2  * Copyright (c) 2015 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.itm.listeners.cache;
9
10 import javax.annotation.PostConstruct;
11 import javax.annotation.PreDestroy;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
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.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
17 import org.opendaylight.genius.itm.globals.ITMConstants;
18 import org.opendaylight.genius.utils.cache.DataStoreCache;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Created by edimjai on 8/4/2016.
26  */
27 @Singleton
28 public class ItmMonitoringListener  extends AsyncClusteredDataTreeChangeListenerBase<TunnelMonitorParams, ItmMonitoringListener>
29 {
30
31
32   private static final Logger logger = LoggerFactory.getLogger(ItmMonitoringListener.class);
33
34   @Inject
35   public ItmMonitoringListener(final DataBroker dataBroker) {
36     super(TunnelMonitorParams.class, ItmMonitoringListener.class);
37     DataStoreCache.create(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME);
38
39     try {
40       registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
41     } catch (final Exception e) {
42       logger.error("ItmMonitoring DataChange listener registration fail!", e);
43     }
44   }
45
46   @PostConstruct
47   public void start() throws Exception {
48     logger.info("ItmMonitoring Started");
49   }
50
51   @PreDestroy
52   public void close() throws Exception {
53     logger.info("ItmMonitoring Closed");
54   }
55
56   @Override
57   protected void remove(InstanceIdentifier<TunnelMonitorParams> key, TunnelMonitorParams dataObjectModification) {
58     DataStoreCache.remove(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME, "MonitorParams");
59   }
60
61   @Override
62   protected void update(InstanceIdentifier<TunnelMonitorParams> identifier, TunnelMonitorParams original,
63                         TunnelMonitorParams update) {
64     DataStoreCache.add(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME, "MonitorParams", update);
65   }
66
67   @Override
68   protected void add(InstanceIdentifier<TunnelMonitorParams> identifier, TunnelMonitorParams add) {
69     DataStoreCache.add(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME, "MonitorParams", add);
70
71
72   }
73
74   @Override protected InstanceIdentifier<TunnelMonitorParams> getWildCardPath() {
75     return InstanceIdentifier.create(TunnelMonitorParams.class);
76   }
77
78   @Override
79   protected ItmMonitoringListener getDataTreeChangeListener() {
80     return this;
81   }
82
83 }