5733c6a185a219f3e22d20c66fdb6ac0f8dc1fba
[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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import javax.annotation.PreDestroy;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.apache.aries.blueprint.annotation.service.Reference;
15 import org.opendaylight.mdsal.binding.api.NotificationService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.config.rev160511.TopologyLldpDiscoveryConfig;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18 import org.opendaylight.yangtools.yang.binding.NotificationListener;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 @Singleton
23 public class LLDPActivator implements AutoCloseable {
24     private static final Logger LOG = LoggerFactory.getLogger(LLDPActivator.class);
25
26     private static String lldpSecureKey;
27
28     private final ListenerRegistration<NotificationListener> lldpNotificationRegistration;
29
30     @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
31     @Inject
32     public LLDPActivator(@Reference NotificationService notificationService,
33                          LLDPDiscoveryListener lldpDiscoveryListener,
34                          TopologyLldpDiscoveryConfig topologyLldpDiscoveryConfig) {
35         lldpSecureKey = topologyLldpDiscoveryConfig.getLldpSecureKey();
36
37         LOG.info("Starting LLDPActivator with lldpSecureKey: {}", lldpSecureKey);
38
39         lldpNotificationRegistration = notificationService.registerNotificationListener(lldpDiscoveryListener);
40
41         LOG.info("LLDPDiscoveryListener started.");
42     }
43
44     @Override
45     @PreDestroy
46     public void close() {
47         lldpNotificationRegistration.close();
48
49         LOG.info("LLDPDiscoveryListener stopped.");
50     }
51
52     public static String getLldpSecureKey() {
53         return lldpSecureKey;
54     }
55 }