Merge "Bug 509: Fixed incorrect merging of Data Store Writes / Events"
[controller.git] / opendaylight / md-sal / topology-manager / src / main / java / org / opendaylight / md / controller / topology / manager / FlowCapableTopologyProvider.xtend
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.NotificationProviderService
11 import org.opendaylight.controller.sal.binding.api.data.DataProviderService
12 import org.opendaylight.yangtools.concepts.Registration
13 import org.opendaylight.yangtools.yang.binding.NotificationListener
14 import org.slf4j.LoggerFactory
15 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext
17 import org.osgi.framework.BundleContext;
18
19 class FlowCapableTopologyProvider extends AbstractBindingAwareProvider implements AutoCloseable {
20
21
22
23     static val LOG = LoggerFactory.getLogger(FlowCapableTopologyProvider);
24
25     @Property
26     DataProviderService dataService;        
27
28     @Property
29     NotificationProviderService notificationService;
30
31     val FlowCapableTopologyExporter exporter = new FlowCapableTopologyExporter();
32
33     Registration<NotificationListener> listenerRegistration
34     
35     override close() {
36        LOG.info("FlowCapableTopologyProvider stopped.");
37         listenerRegistration?.close();
38     }
39
40      /**
41        * Gets called on start of a bundle.
42        * @param session
43        */
44     override onSessionInitiated(ProviderContext session) {
45         dataService = session.getSALService(DataProviderService)
46         notificationService = session.getSALService(NotificationProviderService)
47         exporter.setDataService(dataService);
48         exporter.start();
49         listenerRegistration = notificationService.registerNotificationListener(exporter);
50     }
51
52     /**
53       * Gets called during stop bundle
54       * @param context The execution context of the bundle being stopped.
55       */
56     override stopImpl(BundleContext context) {
57         close();
58     }
59     
60 }
61
62