Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingBrokerWiring.java
1 /*
2  * Copyright (c) 2018 Red Hat, 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.md.sal.binding.impl;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
12 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
13 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
14 import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners;
15 import org.opendaylight.controller.md.sal.binding.compat.HeliumRpcProviderRegistry;
16 import org.opendaylight.controller.md.sal.binding.spi.AdapterFactory;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
18 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
19 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
20 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
21 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
22 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
23 import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
24 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
25 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
26 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
27 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
28 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
29 import org.opendaylight.yangtools.concepts.ListenerRegistration;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
31
32 /**
33  * Provides the implementations of the APIs.
34  *
35  * <p>Intended to be usable in a standalone environment (non-OSGi/Karaf). Also
36  * internally used by the Blueprint XML to expose the same as OSGi services.
37  * This class does not require (depend on) the Guice dependency injection
38  * framework, but can we used with it.
39  *
40  * @author Michael Vorburger.ch, partially based on refactored code originally by Thomas Pantelis
41  */
42 @Deprecated
43 public class BindingBrokerWiring implements AutoCloseable {
44
45     private final BindingToNormalizedNodeCodec bindingToNormalizedNodeCodec;
46     private final ListenerRegistration<SchemaContextListener> mappingCodecListenerReg;
47     private final RpcProviderRegistry rpcProviderRegistry;
48     private final MountPointService mountPointService;
49     private final NotificationService notificationService;
50     private final NotificationPublishService notificationPublishService;
51     private final HeliumNotificationProviderServiceWithInterestListeners notificationAndProviderService;
52     private final AdapterFactory adapterFactory;
53     private final DataBroker dataBroker;
54     private final DataBroker pingPongDataBroker;
55
56     public BindingBrokerWiring(ClassLoadingStrategy classLoadingStrategy, DOMSchemaService schemaService,
57             DOMRpcService domRpcService, DOMRpcProviderService domRpcProviderService,
58             DOMMountPointService domMountPointService, DOMNotificationService domNotificationService,
59             DOMNotificationPublishService domNotificationPublishService,
60             DOMNotificationSubscriptionListenerRegistry domNotificationListenerRegistry, DOMDataBroker domDataBroker,
61             DOMDataBroker domPingPongDataBroker) {
62         // Runtime binding/normalized mapping service
63         BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry();
64         bindingToNormalizedNodeCodec = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true);
65
66         // Register the BindingToNormalizedNodeCodec with the SchemaService as a SchemaContextListener
67         mappingCodecListenerReg = schemaService.registerSchemaContextListener(bindingToNormalizedNodeCodec);
68
69         // Binding RPC Registry Service
70         BindingDOMRpcServiceAdapter bindingDOMRpcServiceAdapter
71             = new BindingDOMRpcServiceAdapter(domRpcService, bindingToNormalizedNodeCodec);
72         BindingDOMRpcProviderServiceAdapter bindingDOMRpcProviderServiceAdapter
73             = new BindingDOMRpcProviderServiceAdapter(domRpcProviderService, bindingToNormalizedNodeCodec);
74         rpcProviderRegistry
75             = new HeliumRpcProviderRegistry(bindingDOMRpcServiceAdapter, bindingDOMRpcProviderServiceAdapter);
76
77         // Binding MountPoint Service
78         mountPointService = new BindingDOMMountPointServiceAdapter(domMountPointService, bindingToNormalizedNodeCodec);
79
80         // Binding Notification Service
81         BindingDOMNotificationServiceAdapter notificationServiceImpl = new BindingDOMNotificationServiceAdapter(
82                 bindingToNormalizedNodeCodec.getCodecRegistry(), domNotificationService);
83         notificationService = notificationServiceImpl;
84         BindingDOMNotificationPublishServiceAdapter notificationPublishServiceImpl =
85                 new BindingDOMNotificationPublishServiceAdapter(
86                         bindingToNormalizedNodeCodec, domNotificationPublishService);
87         notificationPublishService = notificationPublishServiceImpl;
88         notificationAndProviderService = new HeliumNotificationProviderServiceWithInterestListeners(
89                 notificationPublishServiceImpl, notificationServiceImpl, domNotificationListenerRegistry);
90
91         adapterFactory = new BindingToDOMAdapterFactory(bindingToNormalizedNodeCodec);
92
93         // Binding DataBroker
94         dataBroker = adapterFactory.createDataBroker(domDataBroker);
95
96         // Binding PingPong DataBroker
97         pingPongDataBroker = adapterFactory.createDataBroker(domPingPongDataBroker);
98     }
99
100     @Override
101     public void close() throws Exception {
102         mappingCodecListenerReg.close();
103     }
104
105     public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() {
106         return bindingToNormalizedNodeCodec;
107     }
108
109     public AdapterFactory getAdapterFactory() {
110         return adapterFactory;
111     }
112
113     public RpcProviderRegistry getRpcProviderRegistry() {
114         return rpcProviderRegistry;
115     }
116
117     public MountPointService getMountPointService() {
118         return mountPointService;
119     }
120
121     public NotificationService getNotificationService() {
122         return notificationService;
123     }
124
125     public NotificationPublishService getNotificationPublishService() {
126         return notificationPublishService;
127     }
128
129     @Deprecated
130     public NotificationProviderService getNotificationProviderService() {
131         return notificationAndProviderService;
132     }
133
134     @Deprecated
135     public org.opendaylight.controller.sal.binding.api.NotificationService getDeprecatedNotificationService() {
136         return notificationAndProviderService;
137     }
138
139     public DataBroker getDataBroker() {
140         return dataBroker;
141     }
142
143     public DataBroker getPingPongDataBroker() {
144         return pingPongDataBroker;
145     }
146
147 }