Fixes for stale versions and bug in NextHop
[vpnservice.git] / nexthopmgr / nexthopmgr-impl / src / main / java / org / opendaylight / vpnservice / nexthopmgr / NexthopmgrProvider.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.vpnservice.nexthopmgr;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
13 import org.opendaylight.vpnservice.nexthopmgr.NexthopManager;
14 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
15 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
16 import org.opendaylight.idmanager.IdManager;
17
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class NexthopmgrProvider implements BindingAwareProvider, AutoCloseable {
22
23     private static final Logger LOG = LoggerFactory.getLogger(NexthopmgrProvider.class);
24     private VpnInterfaceChangeListener vpnIfListener;
25     private OdlInterfaceChangeListener odlIfListener;
26     private NexthopManager nhManager;
27     private IMdsalApiManager mdsalManager;
28     private IInterfaceManager interfaceManager;
29     private IdManager idManager;
30
31     @Override
32     public void onSessionInitiated(ProviderContext session) {
33         final  DataBroker dbx = session.getSALService(DataBroker.class);
34         nhManager = new NexthopManager(dbx);
35         vpnIfListener = new VpnInterfaceChangeListener(dbx, nhManager);
36         odlIfListener = new OdlInterfaceChangeListener(dbx, nhManager, interfaceManager);
37         idManager = new IdManager(dbx);
38         nhManager.setMdsalManager(mdsalManager);
39         nhManager.setInterfaceManager(interfaceManager);
40         nhManager.setIdManager(idManager);
41         nhManager.createNexthopPointerPool();
42         LOG.info("NexthopmgrProvider Session Initiated");
43     }
44
45     public void setMdsalManager(IMdsalApiManager mdsalManager) {
46         this.mdsalManager = mdsalManager;
47     }
48
49     public void setInterfaceManager(IInterfaceManager interfaceManager) {
50         this.interfaceManager = interfaceManager;
51     }
52
53     @Override
54     public void close() throws Exception {
55         vpnIfListener.close();
56         odlIfListener.close();
57         nhManager.close();
58         LOG.info("NexthopmgrProvider Closed");
59     }
60
61 }