Fixed discard-changes for mdsal netconf, mapping code cleanup.
[controller.git] / opendaylight / md-sal / topology-lldp-discovery / src / main / java / org / opendaylight / md / controller / topology / lldp / LLDPDiscoveryProvider.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.md.controller.topology.lldp;
9
10 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
11 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
12 import org.opendaylight.yangtools.concepts.ListenerRegistration;
13 import org.opendaylight.yangtools.yang.binding.NotificationListener;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class LLDPDiscoveryProvider implements AutoCloseable {
18     private final static Logger LOG =  LoggerFactory.getLogger(LLDPDiscoveryProvider.class);
19     private DataProviderService dataService;
20     private NotificationProviderService notificationService;
21     private final LLDPDiscoveryListener commiter = new LLDPDiscoveryListener(LLDPDiscoveryProvider.this);
22     private ListenerRegistration<NotificationListener> listenerRegistration;
23
24     public DataProviderService getDataService() {
25         return this.dataService;
26     }
27
28     public void setDataService(final DataProviderService dataService) {
29         this.dataService = dataService;
30     }
31
32     public NotificationProviderService getNotificationService() {
33         return this.notificationService;
34     }
35
36     public void setNotificationService(final NotificationProviderService notificationService) {
37         this.notificationService = notificationService;
38     }
39
40     public void start() {
41         ListenerRegistration<NotificationListener> registerNotificationListener = this.getNotificationService().registerNotificationListener(this.commiter);
42         this.listenerRegistration = registerNotificationListener;
43         LLDPLinkAger.getInstance().setManager(this);
44         LOG.info("LLDPDiscoveryListener Started.");
45     }
46
47     public void close() {
48         try {
49             LOG.info("LLDPDiscoveryListener stopped.");
50             if (this.listenerRegistration!=null) {
51                 this.listenerRegistration.close();
52             }
53             LLDPLinkAger.getInstance().close();
54         } catch (Exception e) {
55             throw new Error(e);
56         }
57     }
58 }