Merge "BgpManager commit for code refactoring & bug fixes"
[vpnservice.git] / vpnmanager / vpnmanager-impl / src / main / java / org / opendaylight / vpnservice / VpnserviceProvider.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;
9
10 import java.util.Collections;
11
12 import org.opendaylight.bgpmanager.api.IBgpManager;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class VpnserviceProvider implements BindingAwareProvider,
20                                                        AutoCloseable {
21
22     private static final Logger LOG = LoggerFactory.getLogger(VpnserviceProvider.class);
23     private VpnInterfaceManager vpnInterfaceManager;
24     private VpnManager vpnManager;
25     private IBgpManager bgpManager;
26
27     @Override
28     public void onSessionInitiated(ProviderContext session) {
29         LOG.info("VpnserviceProvider Session Initiated");
30         try {
31             final  DataBroker dataBroker = session.getSALService(DataBroker.class);
32             vpnManager = new VpnManager(dataBroker);
33             vpnInterfaceManager = new VpnInterfaceManager(dataBroker);
34         } catch (Exception e) {
35             LOG.error("Error initializing services", e);
36         }
37     }
38
39     public void setBgpManager(IBgpManager bgpManager) {
40         LOG.debug("BGP Manager reference initialized");
41         this.bgpManager = bgpManager;
42     }
43
44     @Override
45     public void close() throws Exception {
46         vpnManager.close();
47         vpnInterfaceManager.close();
48     }
49 }