MDSAL-API Migration
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / itmdirecttunnels / listeners / TunnelListenerCreator.java
1 /*
2  * Copyright (c) 2018 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.itmdirecttunnels.listeners;
9
10 import javax.inject.Inject;
11 import javax.inject.Singleton;
12 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
13 import org.opendaylight.genius.itm.cache.BfdStateCache;
14 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
15 import org.opendaylight.genius.itm.cache.DpnTepStateCache;
16 import org.opendaylight.genius.itm.cache.OvsBridgeEntryCache;
17 import org.opendaylight.genius.itm.cache.TunnelStateCache;
18 import org.opendaylight.genius.itm.cache.UnprocessedNodeConnectorCache;
19 import org.opendaylight.genius.itm.cache.UnprocessedNodeConnectorEndPointCache;
20 import org.opendaylight.genius.itm.itmdirecttunnels.renderer.ovs.utilities.DirectTunnelUtils;
21 import org.opendaylight.genius.itm.listeners.RemoteDpnListener;
22 import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
23 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
24 import org.opendaylight.mdsal.binding.api.DataBroker;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 @Singleton
29 public class TunnelListenerCreator implements AutoCloseable {
30
31     private static final Logger LOG = LoggerFactory.getLogger(TunnelListenerCreator.class);
32
33     private final TunnelTopologyStateListener tunnelTopologyStateListener;
34     private final TunnelInventoryStateListener tunnelInventoryStateListener;
35     private final TerminationPointStateListener terminationPointStateListener;
36     private final InterfaceConfigListener interfaceConfigListener;
37     private final InternalTunnelListener internalTunnelListener;
38     private final RemoteDpnListener remoteDpnListener;
39
40     @Inject
41     public TunnelListenerCreator(final DataBroker dataBroker,
42                                  final JobCoordinator coordinator,
43                                  final EntityOwnershipUtils entityOwnershipUtils,
44                                  final IInterfaceManager interfaceManager,
45                                  final DirectTunnelUtils directTunnelUtils,
46                                  final BfdStateCache bfdStateCache,
47                                  final DpnTepStateCache dpnTepStateCache,
48                                  final DPNTEPsInfoCache dpntePsInfoCache,
49                                  final OvsBridgeEntryCache ovsBridgeEntryCache,
50                                  final TunnelStateCache tunnelStateCache,
51                                  final UnprocessedNodeConnectorCache unprocessedNodeConnectorCache,
52                                  final UnprocessedNodeConnectorEndPointCache
53                                     unprocessedNodeConnectorEndPointCache) {
54         if (interfaceManager.isItmDirectTunnelsEnabled()) {
55             LOG.debug("ITM Direct Tunnels is enabled. Initializing the listeners");
56             this.tunnelTopologyStateListener = new TunnelTopologyStateListener(dataBroker, coordinator,
57                 directTunnelUtils, dpnTepStateCache, ovsBridgeEntryCache);
58             this.tunnelInventoryStateListener = new TunnelInventoryStateListener(dataBroker, coordinator,
59                 tunnelStateCache, dpnTepStateCache, dpntePsInfoCache, unprocessedNodeConnectorCache,
60                 unprocessedNodeConnectorEndPointCache, directTunnelUtils);
61             this.terminationPointStateListener = new TerminationPointStateListener(dataBroker, entityOwnershipUtils,
62                 coordinator, bfdStateCache, dpnTepStateCache,tunnelStateCache);
63             this.interfaceConfigListener = new InterfaceConfigListener(dataBroker, coordinator);
64             this.internalTunnelListener = new InternalTunnelListener(dataBroker, coordinator);
65             this.remoteDpnListener = new RemoteDpnListener(dataBroker, dpnTepStateCache);
66         } else {
67             LOG.debug("ITM Direct Tunnels is disabled. Listeners are not registered");
68             this.tunnelTopologyStateListener = null;
69             this.tunnelInventoryStateListener = null;
70             this.terminationPointStateListener = null;
71             this.interfaceConfigListener = null;
72             this.internalTunnelListener = null;
73             this.remoteDpnListener = null;
74         }
75     }
76
77     @Override
78     public void close() throws Exception {
79         if (tunnelTopologyStateListener != null) {
80             this.tunnelTopologyStateListener.close();
81         }
82         if (tunnelInventoryStateListener != null) {
83             this.tunnelInventoryStateListener.close();
84         }
85         if (terminationPointStateListener != null) {
86             this.terminationPointStateListener.close();
87         }
88         if (interfaceConfigListener != null) {
89             this.interfaceConfigListener.close();
90         }
91         if (internalTunnelListener != null) {
92             this.internalTunnelListener.close();
93         }
94         if (remoteDpnListener != null) {
95             this.remoteDpnListener.close();
96         }
97     }
98 }