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