Merge "Bug 615: Removed xtend from Topology Manager"
[controller.git] / opendaylight / md-sal / topology-manager / src / main / java / org / opendaylight / md / controller / topology / manager / FlowCapableTopologyProvider.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.manager;
9
10 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
12 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
13 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
14 import org.opendaylight.yangtools.concepts.Registration;
15 import org.opendaylight.yangtools.yang.binding.NotificationListener;
16 import org.osgi.framework.BundleContext;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class FlowCapableTopologyProvider extends AbstractBindingAwareProvider implements AutoCloseable {
21     private final static Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyProvider.class);
22
23     private DataProviderService dataService;
24
25     public DataProviderService getDataService() {
26         return this.dataService;
27     }
28
29     public void setDataService(final DataProviderService dataService) {
30         this.dataService = dataService;
31     }
32
33     private NotificationProviderService notificationService;
34
35     public NotificationProviderService getNotificationService() {
36         return this.notificationService;
37     }
38
39     public void setNotificationService(final NotificationProviderService notificationService) {
40         this.notificationService = notificationService;
41     }
42
43     private final FlowCapableTopologyExporter exporter = new FlowCapableTopologyExporter();
44     private Registration<NotificationListener> listenerRegistration;
45
46     @Override
47     public void close() {
48
49         FlowCapableTopologyProvider.LOG.info("FlowCapableTopologyProvider stopped.");
50         dataService = null;
51         notificationService = null;
52         if (this.listenerRegistration != null) {
53             try {
54                 this.listenerRegistration.close();
55             } catch (Exception e) {
56                 throw new IllegalStateException("Exception during close of listener registration.",e);
57             }
58         }
59     }
60
61     /**
62      * Gets called on start of a bundle.
63      *
64      * @param session
65      */
66     @Override
67     public void onSessionInitiated(final ProviderContext session) {
68         dataService = session.getSALService(DataProviderService.class);
69         notificationService = session.getSALService(NotificationProviderService.class);
70         this.exporter.setDataService(dataService);
71         this.exporter.start();
72         this.listenerRegistration = notificationService.registerNotificationListener(this.exporter);
73         ;
74     }
75
76     /**
77      * Gets called during stop bundle
78      *
79      * @param context
80      *            The execution context of the bundle being stopped.
81      */
82     @Override
83     public void stopImpl(final BundleContext context) {
84         this.close();
85     }
86 }