Migrate topology-lldp-discovery to simplified Listener
[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.opendaylight.mdsal.binding.api.NotificationService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
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.Registration;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 @Singleton
22 public class LLDPActivator implements AutoCloseable {
23     private static final Logger LOG = LoggerFactory.getLogger(LLDPActivator.class);
24
25     private static String lldpSecureKey;
26
27     private final Registration lldpNotificationRegistration;
28
29     @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
30     @Inject
31     public LLDPActivator(NotificationService notificationService,
32                          LLDPDiscoveryListener lldpDiscoveryListener,
33                          TopologyLldpDiscoveryConfig topologyLldpDiscoveryConfig) {
34         lldpSecureKey = topologyLldpDiscoveryConfig.getLldpSecureKey();
35
36         LOG.info("Starting LLDPActivator with lldpSecureKey: {}", lldpSecureKey);
37
38         lldpNotificationRegistration =
39             notificationService.registerListener(PacketReceived.class, 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 }