Bug 3135 - Fixed support for InterestListener
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / NotificationBrokerImplModule.java
1 /*
2  * Copyright (c) 2014 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.controller.config.yang.md.sal.binding.impl;
9
10 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
11 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
12 import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter;
13 import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners;
14 import org.opendaylight.controller.md.sal.binding.compat.HydrogenNotificationBrokerImpl;
15 import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
16 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
17 import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
18 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
19
20 /**
21 *
22 */
23 public final class NotificationBrokerImplModule extends
24         org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractNotificationBrokerImplModule {
25
26     public NotificationBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
27             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
28         super(identifier, dependencyResolver);
29     }
30
31     public NotificationBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
32             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
33             final NotificationBrokerImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
34         super(identifier, dependencyResolver, oldModule, oldInstance);
35     }
36
37     @Override
38     public void validate() {
39         super.validate();
40         // Add custom validation for module attributes here.
41     }
42
43     @Override
44     public java.lang.AutoCloseable createInstance() {
45
46         final NotificationPublishService notificationPublishService = getNotificationPublishAdapterDependency();
47         final NotificationService notificationService = getNotificationAdapterDependency();
48
49         if(notificationPublishService != null & notificationService != null) {
50             return createHeliumAdapter(notificationPublishService,notificationService);
51         }
52
53         /*
54          *  FIXME: Switch to new broker (which has different threading model)
55          *  once this change is communicated with downstream users or
56          *  we will have adapter implementation which will honor Helium
57          *  threading model for notifications.
58          */
59         return new HydrogenNotificationBrokerImpl(SingletonHolder.getDefaultNotificationExecutor());
60     }
61
62     private static AutoCloseable createHeliumAdapter(final NotificationPublishService publishService,
63             final NotificationService listenService) {
64         if(publishService instanceof BindingDOMNotificationPublishServiceAdapter) {
65             final BindingDOMNotificationPublishServiceAdapter casted = (BindingDOMNotificationPublishServiceAdapter) publishService;
66             final DOMNotificationPublishService domService = casted.getDomPublishService();
67             if(domService instanceof DOMNotificationSubscriptionListenerRegistry) {
68                 final DOMNotificationSubscriptionListenerRegistry subsRegistry = (DOMNotificationSubscriptionListenerRegistry) domService;
69                 return new HeliumNotificationProviderServiceWithInterestListeners(publishService, listenService, casted.getCodecRegistry(), subsRegistry);
70             }
71         }
72         return new HeliumNotificationProviderServiceAdapter(publishService, listenService);
73     }
74 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.