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 javassist.ClassPool;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
13 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
14 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
15 import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners;
16 import org.opendaylight.controller.md.sal.binding.compat.HeliumRpcProviderRegistry;
17 import org.opendaylight.controller.md.sal.binding.spi.AdapterFactory;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
19 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
20 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
21 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
22 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
23 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
24 import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
25 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
26 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
27 import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator;
28 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
29 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
30 import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
31 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
32 import org.opendaylight.yangtools.concepts.ListenerRegistration;
33 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
36 * Provides the implementations of the APIs.
38 * <p>Intended to be usable in a standalone environment (non-OSGi/Karaf). Also
39 * internally used by the Blueprint XML to expose the same as OSGi services.
40 * This class does not require (depend on) the Guice dependency injection
41 * framework, but can we used with it.
43 * @author Michael Vorburger.ch, partially based on refactored code originally by Thomas Pantelis
45 public class BindingBrokerWiring implements AutoCloseable {
47 private static final JavassistUtils JAVASSIST = JavassistUtils.forClassPool(ClassPool.getDefault());
49 private final BindingToNormalizedNodeCodec bindingToNormalizedNodeCodec;
50 private final ListenerRegistration<SchemaContextListener> mappingCodecListenerReg;
51 private final RpcProviderRegistry rpcProviderRegistry;
52 private final MountPointService mountPointService;
53 private final NotificationService notificationService;
54 private final NotificationPublishService notificationPublishService;
55 private final HeliumNotificationProviderServiceWithInterestListeners notificationAndProviderService;
56 private final AdapterFactory adapterFactory;
57 private final DataBroker dataBroker;
58 private final DataBroker pingPongDataBroker;
60 public BindingBrokerWiring(ClassLoadingStrategy classLoadingStrategy, DOMSchemaService schemaService,
61 DOMRpcService domRpcService, DOMRpcProviderService domRpcProviderService,
62 DOMMountPointService domMountPointService, DOMNotificationService domNotificationService,
63 DOMNotificationPublishService domNotificationPublishService,
64 DOMNotificationSubscriptionListenerRegistry domNotificationListenerRegistry, DOMDataBroker domDataBroker,
65 DOMDataBroker domPingPongDataBroker) {
66 // Runtime binding/normalized mapping service
67 BindingNormalizedNodeCodecRegistry codecRegistry
68 = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JAVASSIST));
69 bindingToNormalizedNodeCodec = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true);
71 // Register the BindingToNormalizedNodeCodec with the SchemaService as a SchemaContextListener
72 mappingCodecListenerReg = schemaService.registerSchemaContextListener(bindingToNormalizedNodeCodec);
74 // Binding RPC Registry Service
75 BindingDOMRpcServiceAdapter bindingDOMRpcServiceAdapter
76 = new BindingDOMRpcServiceAdapter(domRpcService, bindingToNormalizedNodeCodec);
77 BindingDOMRpcProviderServiceAdapter bindingDOMRpcProviderServiceAdapter
78 = new BindingDOMRpcProviderServiceAdapter(domRpcProviderService, bindingToNormalizedNodeCodec);
80 = new HeliumRpcProviderRegistry(bindingDOMRpcServiceAdapter, bindingDOMRpcProviderServiceAdapter);
82 // Binding MountPoint Service
83 mountPointService = new BindingDOMMountPointServiceAdapter(domMountPointService, bindingToNormalizedNodeCodec);
85 // Binding Notification Service
86 BindingDOMNotificationServiceAdapter notificationServiceImpl = new BindingDOMNotificationServiceAdapter(
87 bindingToNormalizedNodeCodec.getCodecRegistry(), domNotificationService);
88 notificationService = notificationServiceImpl;
89 BindingDOMNotificationPublishServiceAdapter notificationPublishServiceImpl =
90 new BindingDOMNotificationPublishServiceAdapter(
91 bindingToNormalizedNodeCodec, domNotificationPublishService);
92 notificationPublishService = notificationPublishServiceImpl;
93 notificationAndProviderService = new HeliumNotificationProviderServiceWithInterestListeners(
94 notificationPublishServiceImpl, notificationServiceImpl, domNotificationListenerRegistry);
96 adapterFactory = new BindingToDOMAdapterFactory(bindingToNormalizedNodeCodec);
99 dataBroker = adapterFactory.createDataBroker(domDataBroker);
101 // Binding PingPong DataBroker
102 pingPongDataBroker = adapterFactory.createDataBroker(domPingPongDataBroker);
106 public void close() throws Exception {
107 mappingCodecListenerReg.close();
110 public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() {
111 return bindingToNormalizedNodeCodec;
114 public AdapterFactory getAdapterFactory() {
115 return adapterFactory;
118 public RpcProviderRegistry getRpcProviderRegistry() {
119 return rpcProviderRegistry;
122 public MountPointService getMountPointService() {
123 return mountPointService;
126 public NotificationService getNotificationService() {
127 return notificationService;
130 public NotificationPublishService getNotificationPublishService() {
131 return notificationPublishService;
135 public NotificationProviderService getNotificationProviderService() {
136 return notificationAndProviderService;
140 public org.opendaylight.controller.sal.binding.api.NotificationService getDeprecatedNotificationService() {
141 return notificationAndProviderService;
144 public DataBroker getDataBroker() {
148 public DataBroker getPingPongDataBroker() {
149 return pingPongDataBroker;