79f100fa0730915b80b8aa0238055afe28efc8fe
[openflowplugin.git] / applications / topology-lldp-discovery / src / main / java / org / opendaylight / openflowplugin / applications / topology / lldp / LLDPActivator.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.openflowplugin.applications.topology.lldp;
9
10 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
12 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
13 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class LLDPActivator implements BindingAwareProvider, AutoCloseable {
18     private static final Logger LOG = LoggerFactory.getLogger(LLDPActivator.class);
19     private static LLDPDiscoveryProvider provider = new LLDPDiscoveryProvider();
20     private static String lldpSecureKey;
21
22     public LLDPActivator(String secureKey) {
23         lldpSecureKey = secureKey;
24     }
25
26     public void onSessionInitiated(final ProviderContext session) {
27         DataProviderService dataService = session.<DataProviderService>getSALService(DataProviderService.class);
28         provider.setDataService(dataService);
29         NotificationProviderService notificationService = session.<NotificationProviderService>getSALService(NotificationProviderService.class);
30         provider.setNotificationService(notificationService);
31         provider.start();
32     }
33
34     @Override
35     public void close() throws Exception {
36         if(provider != null) {
37             try {
38                 provider.close();
39             } catch (Exception e) {
40                 LOG.warn("Exception when closing down topology-lldp-discovery",e);
41             }
42         }
43     }
44
45     public static String getLldpSecureKey() {
46         return lldpSecureKey;
47     }
48 }