From 0a7e4b306b542e73d8dedca5c9ed1943e18c424d Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Wed, 30 May 2018 14:39:21 +0200 Subject: [PATCH] move binding-broker.xml DI into BindingBrokerWiring JIRA: CONTROLLER-1831 Change-Id: I5fdc4f9018276db92ba9ae2eb35688d428383411 Signed-off-by: Michael Vorburger --- .../sal/binding/impl/BindingBrokerWiring.java | 152 ++++++++++++++++++ .../BindingToNormalizedNodeCodecFactory.java | 53 ------ .../opendaylight/blueprint/binding-broker.xml | 120 +++++--------- 3 files changed, 193 insertions(+), 132 deletions(-) create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingBrokerWiring.java delete mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodecFactory.java diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingBrokerWiring.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingBrokerWiring.java new file mode 100644 index 0000000000..782a018c5c --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingBrokerWiring.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.impl; + +import javassist.ClassPool; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.MountPointService; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; +import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners; +import org.opendaylight.controller.md.sal.binding.compat.HeliumRpcProviderRegistry; +import org.opendaylight.controller.md.sal.binding.spi.AdapterFactory; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; +import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator; +import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry; +import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy; +import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; + +/** + * Provides the implementations of the APIs. + * + *

Intended to be usable in a standalone environment (non-OSGi/Karaf). Also + * internally used by the Blueprint XML to expose the same as OSGi services. + * This class does not require (depend on) the Guice dependency injection + * framework, but can we used with it. + * + * @author Michael Vorburger.ch, partially based on refactored code originally by Thomas Pantelis + */ +public class BindingBrokerWiring implements AutoCloseable { + + private static final JavassistUtils JAVASSIST = JavassistUtils.forClassPool(ClassPool.getDefault()); + + private final BindingToNormalizedNodeCodec bindingToNormalizedNodeCodec; + private final ListenerRegistration mappingCodecListenerReg; + private final RpcProviderRegistry rpcProviderRegistry; + private final MountPointService mountPointService; + private final NotificationService notificationService; + private final NotificationPublishService notificationPublishService; + private final HeliumNotificationProviderServiceWithInterestListeners notificationAndProviderService; + private final AdapterFactory adapterFactory; + private final DataBroker dataBroker; + private final DataBroker pingPongDataBroker; + + public BindingBrokerWiring(ClassLoadingStrategy classLoadingStrategy, DOMSchemaService schemaService, + DOMRpcService domRpcService, DOMRpcProviderService domRpcProviderService, + DOMMountPointService domMountPointService, DOMNotificationService domNotificationService, + DOMNotificationPublishService domNotificationPublishService, + DOMNotificationSubscriptionListenerRegistry domNotificationListenerRegistry, DOMDataBroker domDataBroker, + DOMDataBroker domPingPongDataBroker) { + // Runtime binding/normalized mapping service + BindingNormalizedNodeCodecRegistry codecRegistry + = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JAVASSIST)); + bindingToNormalizedNodeCodec = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true); + + // Register the BindingToNormalizedNodeCodec with the SchemaService as a SchemaContextListener + mappingCodecListenerReg = schemaService.registerSchemaContextListener(bindingToNormalizedNodeCodec); + + // Binding RPC Registry Service + BindingDOMRpcServiceAdapter bindingDOMRpcServiceAdapter + = new BindingDOMRpcServiceAdapter(domRpcService, bindingToNormalizedNodeCodec); + BindingDOMRpcProviderServiceAdapter bindingDOMRpcProviderServiceAdapter + = new BindingDOMRpcProviderServiceAdapter(domRpcProviderService, bindingToNormalizedNodeCodec); + rpcProviderRegistry + = new HeliumRpcProviderRegistry(bindingDOMRpcServiceAdapter, bindingDOMRpcProviderServiceAdapter); + + // Binding MountPoint Service + mountPointService = new BindingDOMMountPointServiceAdapter(domMountPointService, bindingToNormalizedNodeCodec); + + // Binding Notification Service + BindingDOMNotificationServiceAdapter notificationServiceImpl = new BindingDOMNotificationServiceAdapter( + bindingToNormalizedNodeCodec.getCodecRegistry(), domNotificationService); + notificationService = notificationServiceImpl; + BindingDOMNotificationPublishServiceAdapter notificationPublishServiceImpl = + new BindingDOMNotificationPublishServiceAdapter( + bindingToNormalizedNodeCodec, domNotificationPublishService); + notificationPublishService = notificationPublishServiceImpl; + notificationAndProviderService = new HeliumNotificationProviderServiceWithInterestListeners( + notificationPublishServiceImpl, notificationServiceImpl, domNotificationListenerRegistry); + + adapterFactory = new BindingToDOMAdapterFactory(bindingToNormalizedNodeCodec); + + // Binding DataBroker + dataBroker = adapterFactory.createDataBroker(domDataBroker); + + // Binding PingPong DataBroker + pingPongDataBroker = adapterFactory.createDataBroker(domPingPongDataBroker); + } + + @Override + public void close() throws Exception { + mappingCodecListenerReg.close(); + } + + public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() { + return bindingToNormalizedNodeCodec; + } + + public AdapterFactory getAdapterFactory() { + return adapterFactory; + } + + public RpcProviderRegistry getRpcProviderRegistry() { + return rpcProviderRegistry; + } + + public MountPointService getMountPointService() { + return mountPointService; + } + + public NotificationService getNotificationService() { + return notificationService; + } + + public NotificationPublishService getNotificationPublishService() { + return notificationPublishService; + } + + @Deprecated + public NotificationProviderService getNotificationProviderService() { + return notificationAndProviderService; + } + + @Deprecated + public org.opendaylight.controller.sal.binding.api.NotificationService getDeprecatedNotificationService() { + return notificationAndProviderService; + } + + public DataBroker getDataBroker() { + return dataBroker; + } + + public DataBroker getPingPongDataBroker() { + return pingPongDataBroker; + } + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodecFactory.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodecFactory.java deleted file mode 100644 index ddb098c17f..0000000000 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodecFactory.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.md.sal.binding.impl; - -import javassist.ClassPool; -import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator; -import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry; -import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy; -import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; - -/** - * Factory class for creating and initializing the BindingToNormalizedNodeCodec instances. - * - * @author Thomas Pantelis - */ -public final class BindingToNormalizedNodeCodecFactory { - private static final JavassistUtils JAVASSIST = JavassistUtils.forClassPool(ClassPool.getDefault()); - - private BindingToNormalizedNodeCodecFactory() { - } - - /** - * Creates a new BindingToNormalizedNodeCodec instance. - * - * @param classLoadingStrategy the ClassLoadingStrategy - * @return the BindingToNormalizedNodeCodec instance - */ - public static BindingToNormalizedNodeCodec newInstance(final ClassLoadingStrategy classLoadingStrategy) { - final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry( - StreamWriterGenerator.create(JAVASSIST)); - return new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true); - } - - /** - * Registers the given instance with the SchemaService as a SchemaContextListener. - * - * @param instance the BindingToNormalizedNodeCodec instance - * @param schemaService the SchemaService. - * @return the ListenerRegistration - */ - public static ListenerRegistration registerInstance( - final BindingToNormalizedNodeCodec instance, final DOMSchemaService schemaService) { - return schemaService.registerSchemaContextListener(instance); - } -} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/resources/org/opendaylight/blueprint/binding-broker.xml b/opendaylight/md-sal/sal-binding-broker/src/main/resources/org/opendaylight/blueprint/binding-broker.xml index e156c1e7a1..8b13c00f96 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/resources/org/opendaylight/blueprint/binding-broker.xml +++ b/opendaylight/md-sal/sal-binding-broker/src/main/resources/org/opendaylight/blueprint/binding-broker.xml @@ -2,23 +2,36 @@ - - - + + + + + + + + + - + - - - - - + + + + + + + + + + + + org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer @@ -30,9 +43,7 @@ - - - + @@ -42,105 +53,56 @@ - - - - - - - - - - - - - - - - - - + - - - - - - + - - - - - - - - - + - - - - - - - + - - - - - - - + + - - - org.opendaylight.controller.sal.binding.api.NotificationProviderService - org.opendaylight.controller.sal.binding.api.NotificationService - - + + - - - - - + - - - - - + + + + + + + -- 2.36.6