Simplify DelayedListenerRegistration functionality 75/55175/2
authorTom Pantelis <tompantelis@gmail.com>
Tue, 18 Apr 2017 06:09:00 +0000 (02:09 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 22 Apr 2017 13:53:28 +0000 (13:53 +0000)
The DelayedListenerRegistration class is abstract with
parameterized sub-classes for the 2 listener types which
don't provide any additional functionality. Consequently
AbstractDataListenerSupport is parameterized with the
DelayedListenerRegistration type with an abstract method
to instantiate the appropriate type.

We can simplify AbstractDataListenerSupport by removing the
type parameter and the abstract method and consequently remove
the 2 DelayedListenerRegistration sub-classes.

Change-Id: I04933753b59748a09c31e0ec5ed4de9666fea364
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDataListenerSupport.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerSupport.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedDataChangeListenerRegistration.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedDataTreeListenerRegistration.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java

index ac7a933..f9995a2 100644 (file)
@@ -19,12 +19,14 @@ import org.opendaylight.controller.cluster.datastore.messages.ListenerRegistrati
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-abstract class AbstractDataListenerSupport<L extends EventListener, M extends ListenerRegistrationMessage,
-        D extends DelayedListenerRegistration<L, M>> extends LeaderLocalDelegateFactory<M> {
+abstract class AbstractDataListenerSupport<L extends EventListener, M extends ListenerRegistrationMessage>
+        extends LeaderLocalDelegateFactory<M> {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private final Collection<D> delayedListenerRegistrations = ConcurrentHashMap.newKeySet();
-    private final Collection<D> delayedListenerOnAllRegistrations = ConcurrentHashMap.newKeySet();
+    private final Collection<DelayedListenerRegistration<L, M>> delayedListenerRegistrations =
+            ConcurrentHashMap.newKeySet();
+    private final Collection<DelayedListenerRegistration<L, M>> delayedListenerOnAllRegistrations =
+            ConcurrentHashMap.newKeySet();
     private final Collection<ActorSelection> leaderOnlyListenerActors = ConcurrentHashMap.newKeySet();
     private final Collection<ActorSelection> allListenerActors = ConcurrentHashMap.newKeySet();
 
@@ -46,16 +48,16 @@ abstract class AbstractDataListenerSupport<L extends EventListener, M extends Li
         }
 
         if (hasLeader) {
-            for (D reg : delayedListenerOnAllRegistrations) {
-                reg.createDelegate(this);
+            for (DelayedListenerRegistration<L, M> reg : delayedListenerOnAllRegistrations) {
+                reg.doRegistration(this);
             }
 
             delayedListenerOnAllRegistrations.clear();
         }
 
         if (isLeader) {
-            for (D reg : delayedListenerRegistrations) {
-                reg.createDelegate(this);
+            for (DelayedListenerRegistration<L, M> reg : delayedListenerRegistrations) {
+                reg.doRegistration(this);
             }
 
             delayedListenerRegistrations.clear();
@@ -73,8 +75,9 @@ abstract class AbstractDataListenerSupport<L extends EventListener, M extends Li
         } else {
             log.debug("{}: Shard is not the leader - delaying registration", persistenceId());
 
-            D delayedReg = newDelayedListenerRegistration(message, registrationActor);
-            Collection<D> delayedRegList;
+            DelayedListenerRegistration<L, M> delayedReg =
+                    new DelayedListenerRegistration<>(message, registrationActor);
+            Collection<DelayedListenerRegistration<L, M>> delayedRegList;
             if (message.isRegisterOnAllInstances()) {
                 delayedRegList = delayedListenerOnAllRegistrations;
             } else {
@@ -120,8 +123,6 @@ abstract class AbstractDataListenerSupport<L extends EventListener, M extends Li
 
     abstract void doRegistration(M message, ActorRef registrationActor);
 
-    protected abstract D newDelayedListenerRegistration(M message, ActorRef registrationActor);
-
     protected abstract Object newRegistrationReplyMessage(ActorRef registrationActor);
 
     protected abstract String logName();
index 6b0d829..fde1bf6 100644 (file)
@@ -17,8 +17,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 final class DataChangeListenerSupport extends AbstractDataListenerSupport<
-        AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>, RegisterChangeListener,
-            DelayedDataChangeListenerRegistration> {
+        AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>, RegisterChangeListener> {
 
     DataChangeListenerSupport(final Shard shard) {
         super(shard);
@@ -40,12 +39,6 @@ final class DataChangeListenerSupport extends AbstractDataListenerSupport<
                             removeListenerActor(listenerActor)), ActorRef.noSender()));
     }
 
-    @Override
-    protected DelayedDataChangeListenerRegistration newDelayedListenerRegistration(RegisterChangeListener message,
-            ActorRef registrationActor) {
-        return new DelayedDataChangeListenerRegistration(message, registrationActor);
-    }
-
     @Override
     protected Object newRegistrationReplyMessage(ActorRef registrationActor) {
         return new RegisterChangeListenerReply(registrationActor);
index 4f70327..f250fb2 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeCh
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
 
 final class DataTreeChangeListenerSupport extends AbstractDataListenerSupport<DOMDataTreeChangeListener,
-        RegisterDataTreeChangeListener, DelayedDataTreeListenerRegistration> {
+        RegisterDataTreeChangeListener> {
 
     DataTreeChangeListenerSupport(final Shard shard) {
         super(shard);
@@ -36,12 +36,6 @@ final class DataTreeChangeListenerSupport extends AbstractDataListenerSupport<DO
                             removeListenerActor(listenerActor)), ActorRef.noSender()));
     }
 
-    @Override
-    protected DelayedDataTreeListenerRegistration newDelayedListenerRegistration(
-            RegisterDataTreeChangeListener message, ActorRef registrationActor) {
-        return new DelayedDataTreeListenerRegistration(message, registrationActor);
-    }
-
     @Override
     protected Object newRegistrationReplyMessage(ActorRef registrationActor) {
         return new RegisterDataTreeChangeListenerReply(registrationActor);
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedDataChangeListenerRegistration.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedDataChangeListenerRegistration.java
deleted file mode 100644 (file)
index a8fe100..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco 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.cluster.datastore;
-
-import akka.actor.ActorRef;
-import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-final class DelayedDataChangeListenerRegistration extends DelayedListenerRegistration<
-           AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>, RegisterChangeListener> {
-
-    DelayedDataChangeListenerRegistration(final RegisterChangeListener registerChangeListener,
-            final ActorRef registrationActor) {
-        super(registerChangeListener, registrationActor);
-    }
-}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedDataTreeListenerRegistration.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedDataTreeListenerRegistration.java
deleted file mode 100644 (file)
index c67115a..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco 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.cluster.datastore;
-
-import akka.actor.ActorRef;
-import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
-
-/**
- * Intermediate proxy registration returned to the user when we cannot
- * instantiate the registration immediately. It provides a bridge to
- * a real registration which may materialize at some point in the future.
- */
-final class DelayedDataTreeListenerRegistration
-        extends DelayedListenerRegistration<DOMDataTreeChangeListener, RegisterDataTreeChangeListener> {
-
-    DelayedDataTreeListenerRegistration(final RegisterDataTreeChangeListener registerTreeChangeListener,
-            final ActorRef registrationActor) {
-        super(registerTreeChangeListener, registrationActor);
-    }
-}
-
index 18d23aa..e1c9f0b 100644 (file)
@@ -13,7 +13,7 @@ import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.cluster.datastore.messages.ListenerRegistrationMessage;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
-abstract class DelayedListenerRegistration<L extends EventListener, M extends ListenerRegistrationMessage>
+class DelayedListenerRegistration<L extends EventListener, M extends ListenerRegistrationMessage>
         implements ListenerRegistration<L> {
     private final M registrationMessage;
     private final ActorRef registrationActor;
@@ -30,7 +30,7 @@ abstract class DelayedListenerRegistration<L extends EventListener, M extends Li
         return registrationMessage;
     }
 
-    synchronized void createDelegate(final AbstractDataListenerSupport<L, M, ?> support) {
+    synchronized void doRegistration(final AbstractDataListenerSupport<L, M> support) {
         if (!closed) {
             support.doRegistration(registrationMessage, registrationActor);
         }

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