Use explicit classes for Listener forwarding 08/78208/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 27 Nov 2018 12:09:30 +0000 (13:09 +0100)
committerTom Pantelis <tompantelis@gmail.com>
Tue, 27 Nov 2018 14:13:44 +0000 (14:13 +0000)
This allows us to use ForwardingObject, which will forward
toString() invocations intact, properly identifying registered
listeners.

Change-Id: I486352d41047b20cb5b2735cff911d7d49aaf963
JIRA: CONTROLLER-1874
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-dom-compat/src/main/java/org/opendaylight/controller/sal/core/compat/LegacyDOMDataBrokerAdapter.java

index b9cd447..cfad179 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.sal.core.compat;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ClassToInstanceMap;
@@ -18,6 +20,7 @@ import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
+import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Supplier;
@@ -53,6 +56,7 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 
 /**
  * Adapter between the legacy controller API-based DOMDataBroker and the mdsal API-based DOMDataBroker.
@@ -99,10 +103,9 @@ public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMD
                         final DOMDataTreeIdentifier treeId, final L listener) {
                     final org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener delegateListener;
                     if (listener instanceof ClusteredDOMDataTreeChangeListener) {
-                        delegateListener = (org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener)
-                            listener::onDataTreeChanged;
+                        delegateListener = new ClusteredProxyListener(listener);
                     } else {
-                        delegateListener = listener::onDataTreeChanged;
+                        delegateListener = new ProxyListener(listener);
                     }
 
                     final ListenerRegistration<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> reg =
@@ -337,4 +340,31 @@ public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMD
             adapter.readDelegate().close();
         }
     }
+
+    private static class ProxyListener extends ForwardingObject
+            implements org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener {
+        private final DOMDataTreeChangeListener delegate;
+
+        ProxyListener(final DOMDataTreeChangeListener delegate) {
+            this.delegate = requireNonNull(delegate);
+        }
+
+        @Override
+        public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
+            delegate.onDataTreeChanged(changes);
+        }
+
+        @Override
+        protected DOMDataTreeChangeListener delegate() {
+            return delegate;
+        }
+    }
+
+    private static final class ClusteredProxyListener extends ProxyListener
+            implements org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener {
+
+        ClusteredProxyListener(DOMDataTreeChangeListener delegate) {
+            super(delegate);
+        }
+    }
 }

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