move binding-broker.xml DI into BindingBrokerWiring 85/72485/12
authorMichael Vorburger <vorburger@redhat.com>
Wed, 30 May 2018 12:39:21 +0000 (14:39 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 3 Oct 2018 14:07:26 +0000 (14:07 +0000)
JIRA: CONTROLLER-1831
Change-Id: I5fdc4f9018276db92ba9ae2eb35688d428383411
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingBrokerWiring.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodecFactory.java [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/resources/org/opendaylight/blueprint/binding-broker.xml

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 (file)
index 0000000..782a018
--- /dev/null
@@ -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.
+ *
+ * <p>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<SchemaContextListener> 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 (file)
index ddb098c..0000000
+++ /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<SchemaContextListener> registerInstance(
-            final BindingToNormalizedNodeCodec instance, final DOMSchemaService schemaService) {
-        return schemaService.registerSchemaContextListener(instance);
-    }
-}
index e156c1e..8b13c00 100644 (file)
@@ -2,23 +2,36 @@
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
            xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
 
-  <!-- Runtime binding/normalized mapping service -->
-
-  <reference id="classLoadingStrategy" interface="org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy"/>
+  <reference id="classLoadingStrategy" interface="org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy" />
   <reference id="schemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService" />
+  <reference id="domRpcService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcService"/>
+  <reference id="domRpcRegistry" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService"/>
+  <reference id="domMountPointService" interface="org.opendaylight.controller.md.sal.dom.api.DOMMountPointService"/>
+  <reference id="domNotificationService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationService"/>
+  <reference id="domNotificationPublishService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService"/>
+  <reference id="domNotificationListenerRegistry" interface="org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry"/>
+  <reference id="domDefaultDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
+          odl:type="default"/>
+  <reference id="domPingPongDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
+          odl:type="pingpong"/>
 
-  <bean id="mappingCodec" class="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodecFactory"
-         factory-method="newInstance">
+  <bean id="wiring" class="org.opendaylight.controller.md.sal.binding.impl.BindingBrokerWiring">
     <argument ref="classLoadingStrategy"/>
-  </bean>
-
-  <!-- Register the BindingToNormalizedNodeCodec with the SchemaService as a SchemaContextListener -->
-  <bean id="mappingCodecListenerReg" class="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodecFactory"
-         factory-method="registerInstance" destroy-method="close">
-    <argument ref="mappingCodec"/>
     <argument ref="schemaService"/>
+    <argument ref="domRpcService"/>
+    <argument ref="domRpcRegistry"/>
+    <argument ref="domMountPointService"/>
+    <argument ref="domNotificationService"/>
+    <argument ref="domNotificationPublishService"/>
+    <argument ref="domNotificationListenerRegistry"/>
+    <argument ref="domDefaultDataBroker"/>
+    <argument ref="domPingPongDataBroker"/>
   </bean>
 
+  <!-- Runtime binding/normalized mapping service -->
+
+  <bean id="mappingCodec" factory-ref="wiring" factory-method="getBindingToNormalizedNodeCodec" />
+
   <service ref="mappingCodec" odl:type="default">
     <interfaces>
       <value>org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer</value>
@@ -30,9 +43,7 @@
   <service id="codec" ref="mappingCodec" interface="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec"/>
 
   <!-- Adapter service -->
-  <bean id="adapterFactory" class="org.opendaylight.controller.md.sal.binding.impl.BindingToDOMAdapterFactory">
-    <argument ref="mappingCodec"/>
-  </bean>
+  <bean id="adapterFactory" factory-ref="wiring" factory-method="getAdapterFactory" />
 
   <service id="factory" ref="adapterFactory">
     <interfaces>
 
   <!-- Binding RPC Registry Service -->
 
-  <reference id="domRpcService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcService"/>
-
-  <bean id="bindingRpcServiceAdapter" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMRpcServiceAdapter" >
-    <argument ref="domRpcService"/>
-    <argument ref="mappingCodec"/>
-  </bean>
-
-  <reference id="domRpcRegistry" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService"/>
-
-  <bean id="bindingRpcProviderAdapter" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMRpcProviderServiceAdapter" >
-    <argument ref="domRpcRegistry"/>
-    <argument ref="mappingCodec"/>
-  </bean>
-
-  <bean id="bindingRpcRegistry" class="org.opendaylight.controller.md.sal.binding.compat.HeliumRpcProviderRegistry" >
-    <argument ref="bindingRpcServiceAdapter"/>
-    <argument ref="bindingRpcProviderAdapter"/>
-  </bean>
+  <bean id="bindingRpcRegistry" factory-ref="wiring" factory-method="getRpcProviderRegistry" />
 
   <service ref="bindingRpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"
           odl:type="default"/>
 
   <!-- Binding MountPoint Service -->
 
-  <reference id="domMountPointService" interface="org.opendaylight.controller.md.sal.dom.api.DOMMountPointService"/>
-
-  <bean id="bindingMountPointService" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMMountPointServiceAdapter" >
-    <argument ref="domMountPointService"/>
-    <argument ref="mappingCodec"/>
-  </bean>
+  <bean id="bindingMountPointService" factory-ref="wiring" factory-method="getMountPointService" />
 
   <service ref="bindingMountPointService" interface="org.opendaylight.controller.md.sal.binding.api.MountPointService"
           odl:type="default"/>
 
   <!-- Binding Notification Service -->
 
-  <reference id="domNotificationService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationService"/>
-
-  <bean id="bindingNotificationServiceAdapter" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationServiceAdapter">
-    <argument>
-      <bean factory-ref="mappingCodec" factory-method="getCodecRegistry"/>
-    </argument>
-    <argument ref="domNotificationService"/>
-  </bean>
-
+  <bean id="bindingNotificationServiceAdapter" factory-ref="wiring" factory-method="getNotificationService" />
   <service ref="bindingNotificationServiceAdapter" interface="org.opendaylight.controller.md.sal.binding.api.NotificationService"
           odl:type="default"/>
 
-  <reference id="domNotificationPublishService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService"/>
-
-  <bean id="bindingNotificationPublishAdapter" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter">
-    <argument ref="mappingCodec"/>
-    <argument ref="domNotificationPublishService"/>
-  </bean>
-
+  <bean id="bindingNotificationPublishAdapter" factory-ref="wiring" factory-method="getNotificationPublishService" />
   <service ref="bindingNotificationPublishAdapter" interface="org.opendaylight.controller.md.sal.binding.api.NotificationPublishService"
           odl:type="default"/>
 
-  <reference id="domNotificationListenerRegistry" interface="org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry"/>
-
-  <bean id="bindingNotificationProviderService" class="org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners">
-    <argument ref="bindingNotificationPublishAdapter"/>
-    <argument ref="bindingNotificationServiceAdapter"/>
-    <argument ref="domNotificationListenerRegistry"/>
-  </bean>
+  <bean id="notificationProviderService" factory-ref="wiring" factory-method="getNotificationProviderService" />
+  <service ref="notificationProviderService" interface="org.opendaylight.controller.sal.binding.api.NotificationProviderService" odl:type="default" />
 
-  <service ref="bindingNotificationProviderService" odl:type="default">
-    <interfaces>
-      <value>org.opendaylight.controller.sal.binding.api.NotificationProviderService</value>
-      <value>org.opendaylight.controller.sal.binding.api.NotificationService</value>
-    </interfaces>
-  </service>
+  <bean id="deprecatedNotificationService" factory-ref="wiring" factory-method="getNotificationProviderService" />
+  <service ref="deprecatedNotificationService" interface="org.opendaylight.controller.sal.binding.api.NotificationService" odl:type="default" />
 
   <!-- Binding DataBroker -->
 
-  <reference id="domDefaultDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
-          odl:type="default"/>
-
-  <bean id="bindingDataBroker" factory-ref="adapterFactory" factory-method="createDataBroker">
-    <argument ref="domDefaultDataBroker"/>
-  </bean>
+  <bean id="bindingDataBroker" factory-ref="wiring" factory-method="getDataBroker" />
 
   <service ref="bindingDataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
           odl:type="default"/>
 
   <!-- Binding PingPong DataBroker -->
 
-  <reference id="domPingPongDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
-          odl:type="pingpong"/>
-
-  <bean id="bindingPingPongDataBroker" factory-ref="adapterFactory" factory-method="createDataBroker">
-    <argument ref="domPingPongDataBroker"/>
-  </bean>
+  <bean id="bindingPingPongDataBroker" factory-ref="wiring" factory-method="getPingPongDataBroker" />
 
   <service ref="bindingPingPongDataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
           odl:type="pingpong"/>
 
   <!-- Legacy BindingAwareBroker -->
 
+  <bean id="bindingNotificationProviderService" class="org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners">
+    <argument ref="bindingNotificationPublishAdapter"/>
+    <argument ref="bindingNotificationServiceAdapter"/>
+    <argument ref="domNotificationListenerRegistry"/>
+  </bean>
+
   <bean id="bindingAwareBroker" class="org.opendaylight.controller.sal.binding.impl.RootBindingAwareBroker"
       init-method="start" destroy-method="close">
     <argument value="deprecated-BindingAwareBroker"/>

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.