916077da44209efce5c9c05f61aa4afd7a202f3d
[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 public class BindingBrokerWiring implements AutoCloseable {
43
44     private final BindingToNormalizedNodeCodec bindingToNormalizedNodeCodec;
45     private final ListenerRegistration<SchemaContextListener> mappingCodecListenerReg;
46     private final RpcProviderRegistry rpcProviderRegistry;
47     private final MountPointService mountPointService;
48     private final NotificationService notificationService;
49     private final NotificationPublishService notificationPublishService;
50     private final HeliumNotificationProviderServiceWithInterestListeners notificationAndProviderService;
51     private final AdapterFactory adapterFactory;
52     private final DataBroker dataBroker;
53     private final DataBroker pingPongDataBroker;
54
55     public BindingBrokerWiring(ClassLoadingStrategy classLoadingStrategy, DOMSchemaService schemaService,
56             DOMRpcService domRpcService, DOMRpcProviderService domRpcProviderService,
57             DOMMountPointService domMountPointService, DOMNotificationService domNotificationService,
58             DOMNotificationPublishService domNotificationPublishService,
59             DOMNotificationSubscriptionListenerRegistry domNotificationListenerRegistry, DOMDataBroker domDataBroker,
60             DOMDataBroker domPingPongDataBroker) {
61         // Runtime binding/normalized mapping service
62         BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry();
63         bindingToNormalizedNodeCodec = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true);
64
65         // Register the BindingToNormalizedNodeCodec with the SchemaService as a SchemaContextListener
66         mappingCodecListenerReg = schemaService.registerSchemaContextListener(bindingToNormalizedNodeCodec);
67
68         // Binding RPC Registry Service
69         BindingDOMRpcServiceAdapter bindingDOMRpcServiceAdapter
70             = new BindingDOMRpcServiceAdapter(domRpcService, bindingToNormalizedNodeCodec);
71         BindingDOMRpcProviderServiceAdapter bindingDOMRpcProviderServiceAdapter
72             = new BindingDOMRpcProviderServiceAdapter(domRpcProviderService, bindingToNormalizedNodeCodec);
73         rpcProviderRegistry
74             = new HeliumRpcProviderRegistry(bindingDOMRpcServiceAdapter, bindingDOMRpcProviderServiceAdapter);
75
76         // Binding MountPoint Service
77         mountPointService = new BindingDOMMountPointServiceAdapter(domMountPointService, bindingToNormalizedNodeCodec);
78
79         // Binding Notification Service
80         BindingDOMNotificationServiceAdapter notificationServiceImpl = new BindingDOMNotificationServiceAdapter(
81                 bindingToNormalizedNodeCodec.getCodecRegistry(), domNotificationService);
82         notificationService = notificationServiceImpl;
83         BindingDOMNotificationPublishServiceAdapter notificationPublishServiceImpl =
84                 new BindingDOMNotificationPublishServiceAdapter(
85                         bindingToNormalizedNodeCodec, domNotificationPublishService);
86         notificationPublishService = notificationPublishServiceImpl;
87         notificationAndProviderService = new HeliumNotificationProviderServiceWithInterestListeners(
88                 notificationPublishServiceImpl, notificationServiceImpl, domNotificationListenerRegistry);
89
90         adapterFactory = new BindingToDOMAdapterFactory(bindingToNormalizedNodeCodec);
91
92         // Binding DataBroker
93         dataBroker = adapterFactory.createDataBroker(domDataBroker);
94
95         // Binding PingPong DataBroker
96         pingPongDataBroker = adapterFactory.createDataBroker(domPingPongDataBroker);
97     }
98
99     @Override
100     public void close() throws Exception {
101         mappingCodecListenerReg.close();
102     }
103
104     public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() {
105         return bindingToNormalizedNodeCodec;
106     }
107
108     public AdapterFactory getAdapterFactory() {
109         return adapterFactory;
110     }
111
112     public RpcProviderRegistry getRpcProviderRegistry() {
113         return rpcProviderRegistry;
114     }
115
116     public MountPointService getMountPointService() {
117         return mountPointService;
118     }
119
120     public NotificationService getNotificationService() {
121         return notificationService;
122     }
123
124     public NotificationPublishService getNotificationPublishService() {
125         return notificationPublishService;
126     }
127
128     @Deprecated
129     public NotificationProviderService getNotificationProviderService() {
130         return notificationAndProviderService;
131     }
132
133     @Deprecated
134     public org.opendaylight.controller.sal.binding.api.NotificationService getDeprecatedNotificationService() {
135         return notificationAndProviderService;
136     }
137
138     public DataBroker getDataBroker() {
139         return dataBroker;
140     }
141
142     public DataBroker getPingPongDataBroker() {
143         return pingPongDataBroker;
144     }
145
146 }