2 * Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.impl;
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;
33 * Provides the implementations of the APIs.
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.
40 * @author Michael Vorburger.ch, partially based on refactored code originally by Thomas Pantelis
43 public class BindingBrokerWiring implements AutoCloseable {
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;
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);
66 // Register the BindingToNormalizedNodeCodec with the SchemaService as a SchemaContextListener
67 mappingCodecListenerReg = schemaService.registerSchemaContextListener(bindingToNormalizedNodeCodec);
69 // Binding RPC Registry Service
70 BindingDOMRpcServiceAdapter bindingDOMRpcServiceAdapter
71 = new BindingDOMRpcServiceAdapter(domRpcService, bindingToNormalizedNodeCodec);
72 BindingDOMRpcProviderServiceAdapter bindingDOMRpcProviderServiceAdapter
73 = new BindingDOMRpcProviderServiceAdapter(domRpcProviderService, bindingToNormalizedNodeCodec);
75 = new HeliumRpcProviderRegistry(bindingDOMRpcServiceAdapter, bindingDOMRpcProviderServiceAdapter);
77 // Binding MountPoint Service
78 mountPointService = new BindingDOMMountPointServiceAdapter(domMountPointService, bindingToNormalizedNodeCodec);
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);
91 adapterFactory = new BindingToDOMAdapterFactory(bindingToNormalizedNodeCodec);
94 dataBroker = adapterFactory.createDataBroker(domDataBroker);
96 // Binding PingPong DataBroker
97 pingPongDataBroker = adapterFactory.createDataBroker(domPingPongDataBroker);
101 public void close() throws Exception {
102 mappingCodecListenerReg.close();
105 public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() {
106 return bindingToNormalizedNodeCodec;
109 public AdapterFactory getAdapterFactory() {
110 return adapterFactory;
113 public RpcProviderRegistry getRpcProviderRegistry() {
114 return rpcProviderRegistry;
117 public MountPointService getMountPointService() {
118 return mountPointService;
121 public NotificationService getNotificationService() {
122 return notificationService;
125 public NotificationPublishService getNotificationPublishService() {
126 return notificationPublishService;
130 public NotificationProviderService getNotificationProviderService() {
131 return notificationAndProviderService;
135 public org.opendaylight.controller.sal.binding.api.NotificationService getDeprecatedNotificationService() {
136 return notificationAndProviderService;
139 public DataBroker getDataBroker() {
143 public DataBroker getPingPongDataBroker() {
144 return pingPongDataBroker;