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
42 public class BindingBrokerWiring implements AutoCloseable {
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;
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);
65 // Register the BindingToNormalizedNodeCodec with the SchemaService as a SchemaContextListener
66 mappingCodecListenerReg = schemaService.registerSchemaContextListener(bindingToNormalizedNodeCodec);
68 // Binding RPC Registry Service
69 BindingDOMRpcServiceAdapter bindingDOMRpcServiceAdapter
70 = new BindingDOMRpcServiceAdapter(domRpcService, bindingToNormalizedNodeCodec);
71 BindingDOMRpcProviderServiceAdapter bindingDOMRpcProviderServiceAdapter
72 = new BindingDOMRpcProviderServiceAdapter(domRpcProviderService, bindingToNormalizedNodeCodec);
74 = new HeliumRpcProviderRegistry(bindingDOMRpcServiceAdapter, bindingDOMRpcProviderServiceAdapter);
76 // Binding MountPoint Service
77 mountPointService = new BindingDOMMountPointServiceAdapter(domMountPointService, bindingToNormalizedNodeCodec);
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);
90 adapterFactory = new BindingToDOMAdapterFactory(bindingToNormalizedNodeCodec);
93 dataBroker = adapterFactory.createDataBroker(domDataBroker);
95 // Binding PingPong DataBroker
96 pingPongDataBroker = adapterFactory.createDataBroker(domPingPongDataBroker);
100 public void close() throws Exception {
101 mappingCodecListenerReg.close();
104 public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() {
105 return bindingToNormalizedNodeCodec;
108 public AdapterFactory getAdapterFactory() {
109 return adapterFactory;
112 public RpcProviderRegistry getRpcProviderRegistry() {
113 return rpcProviderRegistry;
116 public MountPointService getMountPointService() {
117 return mountPointService;
120 public NotificationService getNotificationService() {
121 return notificationService;
124 public NotificationPublishService getNotificationPublishService() {
125 return notificationPublishService;
129 public NotificationProviderService getNotificationProviderService() {
130 return notificationAndProviderService;
134 public org.opendaylight.controller.sal.binding.api.NotificationService getDeprecatedNotificationService() {
135 return notificationAndProviderService;
138 public DataBroker getDataBroker() {
142 public DataBroker getPingPongDataBroker() {
143 return pingPongDataBroker;