Refactor DataBroker adapter wiring 51/73151/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 18 Jun 2018 18:43:39 +0000 (20:43 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Jun 2018 09:11:39 +0000 (11:11 +0200)
We really want to expose a factory, which is able to create adapters
based on a codec.

Create AdapterFactory to serve as such a class and use it as
intermediary for instantiation. This removes reference to binding.impl
classes.

Change-Id: I1cf6867121af1703849db642512776d8ef790ae0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/mdsal-trace/binding-impl/pom.xml
opendaylight/md-sal/mdsal-trace/binding-impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToDOMAdapterFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/spi/AdapterFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/resources/org/opendaylight/blueprint/binding-broker.xml

index 849d0cc..11da07f 100644 (file)
@@ -49,10 +49,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
                 <instructions>
                     <Import-Package>
                       org.opendaylight.controller.md.sal.trace.api,
-                      org.opendaylight.mdsal.binding.generator.api,
                       org.opendaylight.controller.md.sal.dom.api,
                       org.opendaylight.controller.md.sal.binding.api,
-                      org.opendaylight.controller.md.sal.binding.impl,
+                      org.opendaylight.controller.md.sal.binding.spi,
                       org.opendaylight.controller.sal.core.api.model,
                       *
                     </Import-Package>
index 0099543..6f36213 100644 (file)
@@ -16,11 +16,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       interface="org.opendaylight.controller.md.sal.trace.api.TracingDOMDataBroker"
       odl:type="default" />
 
-  <odl:static-reference id="mappingCodec" interface="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec"/>
+  <reference id="adapterFactory" interface="org.opendaylight.controller.md.sal.binding.spi.AdapterFactory"/>
 
-  <bean id="tracingBindingDataBroker" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter">
+  <bean id="tracingBindingDataBroker" factory-ref="adapterFactory" factory-method="createDataBroker">
     <argument ref="tracingDefaultDOMBroker"/>
-    <argument ref="mappingCodec"/>
   </bean>
 
   <service id="tracingBindingDataBrokerSvc" ref="tracingBindingDataBroker"
@@ -31,9 +30,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       interface="org.opendaylight.controller.md.sal.trace.api.TracingDOMDataBroker"
       odl:type="pingpong"/>
 
-  <bean id="bindingTracingPingPongDataBroker" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter">
+  <bean id="bindingTracingPingPongDataBroker" factory-ref="adapterFactory" factory-method="createDataBroker">
     <argument ref="tracingPingPongDOMDataBroker"/>
-    <argument ref="mappingCodec"/>
   </bean>
 
   <service ref="bindingTracingPingPongDataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToDOMAdapterFactory.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToDOMAdapterFactory.java
new file mode 100644 (file)
index 0000000..f1da15c
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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 static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.spi.AdapterFactory;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+
+@Beta
+@NonNullByDefault
+public final class BindingToDOMAdapterFactory implements AdapterFactory {
+    private final BindingToNormalizedNodeCodec codec;
+
+    public BindingToDOMAdapterFactory(final BindingToNormalizedNodeCodec codec) {
+        this.codec = requireNonNull(codec);
+    }
+
+    @Override
+    public DataBroker createDataBroker(final DOMDataBroker domBroker) {
+        return new BindingDOMDataBrokerAdapter(requireNonNull(domBroker), codec);
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/spi/AdapterFactory.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/spi/AdapterFactory.java
new file mode 100644 (file)
index 0000000..5656471
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.spi;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+
+@Beta
+@NonNullByDefault
+public interface AdapterFactory {
+    /**
+     * Return a {@link DataBroker} implementation backed by the specified {@link DOMDataBroker}.
+     *
+     * @param domBroker Backing DOMDataBroker
+     * @return A DataBroker instance.
+     * @throws NullPointerException if {@code domBroker} is null.
+     */
+    DataBroker createDataBroker(DOMDataBroker domBroker);
+}
index 2595420..e156c1e 100644 (file)
     </interfaces>
   </service>
 
+  <!-- TODO: remove this service as it is referring to a class. To do that we need to migrate everyone over to 'factory' -->
   <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>
+
+  <service id="factory" ref="adapterFactory">
+    <interfaces>
+      <value>org.opendaylight.controller.md.sal.binding.spi.AdapterFactory</value>
+    </interfaces>
+  </service>
+
   <!-- Binding RPC Registry Service -->
 
   <reference id="domRpcService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcService"/>
   <reference id="domDefaultDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
           odl:type="default"/>
 
-  <bean id="bindingDataBroker" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter">
+  <bean id="bindingDataBroker" factory-ref="adapterFactory" factory-method="createDataBroker">
     <argument ref="domDefaultDataBroker"/>
-    <argument ref="mappingCodec"/>
   </bean>
 
   <service ref="bindingDataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
   <reference id="domPingPongDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
           odl:type="pingpong"/>
 
-  <bean id="bindingPingPongDataBroker" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter">
+  <bean id="bindingPingPongDataBroker" factory-ref="adapterFactory" factory-method="createDataBroker">
     <argument ref="domPingPongDataBroker"/>
-    <argument ref="mappingCodec"/>
   </bean>
 
   <service ref="bindingPingPongDataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"

©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.