From e78622411319748472b5d9edab14eb6dc92cf6b1 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Tue, 18 Apr 2017 02:32:37 -0400 Subject: [PATCH] Refactor Register*ListenerReply classes The listener-type specific RegisterDataTreeChangeListenerReply and RegisterChangeListenerReply classes are identical. Simplify by replacing them with a general RegisterDataTreeNotificationListenerReply. This also simplifies AbstractDataListenerSupport by eliminating the abstract newRegistrationReplyMessage method. Change-Id: I97f6cf366ae6ff858ff258ebb8479468b144c193 Signed-off-by: Tom Pantelis --- .../AbstractDataListenerSupport.java | 5 +-- .../DataChangeListenerRegistrationProxy.java | 4 +- .../datastore/DataChangeListenerSupport.java | 6 --- .../DataTreeChangeListenerProxy.java | 4 +- .../DataTreeChangeListenerSupport.java | 6 --- .../messages/RegisterChangeListenerReply.java | 24 ----------- ...terDataTreeNotificationListenerReply.java} | 12 +++--- ...taChangeListenerRegistrationProxyTest.java | 8 ++-- .../DataTreeChangeListenerProxyTest.java | 6 +-- .../DataTreeChangeListenerSupportTest.java | 4 +- .../cluster/datastore/ShardTest.java | 41 +++++++++---------- 11 files changed, 42 insertions(+), 78 deletions(-) delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/RegisterChangeListenerReply.java rename opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/{RegisterDataTreeChangeListenerReply.java => RegisterDataTreeNotificationListenerReply.java} (69%) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDataListenerSupport.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDataListenerSupport.java index 15de81e290..5a09b87da1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDataListenerSupport.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDataListenerSupport.java @@ -16,6 +16,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.opendaylight.controller.cluster.datastore.actors.DataTreeNotificationListenerRegistrationActor; import org.opendaylight.controller.cluster.datastore.messages.EnableNotification; import org.opendaylight.controller.cluster.datastore.messages.ListenerRegistrationMessage; +import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,7 +94,7 @@ abstract class AbstractDataListenerSupport ext LOG.error("{}: Failed to register DataTreeChangeListener {} at path {}", logContext(), getInstance(), registeredPath, failure); } else { - RegisterDataTreeChangeListenerReply reply = (RegisterDataTreeChangeListenerReply) result; + RegisterDataTreeNotificationListenerReply reply = (RegisterDataTreeNotificationListenerReply)result; setListenerRegistrationActor(actorContext.actorSelection( reply.getListenerRegistrationPath())); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java index a3ed4a19c9..8dba00547f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java @@ -11,7 +11,6 @@ import akka.actor.ActorRef; import akka.actor.ActorSelection; import org.opendaylight.controller.cluster.datastore.actors.DataTreeNotificationListenerRegistrationActor; import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener; -import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListenerReply; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; final class DataTreeChangeListenerSupport extends AbstractDataListenerSupport> answer = invocation -> { proxy.close(); - return Futures.successful((Object)new RegisterChangeListenerReply(getRef())); + return Futures.successful((Object)new RegisterDataTreeNotificationListenerReply(getRef())); }; doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class), diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java index 820fe5614f..927f929797 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java @@ -34,7 +34,7 @@ import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound; import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound; import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener; -import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListenerReply; +import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.cluster.datastore.utils.Dispatchers; import org.opendaylight.controller.cluster.raft.utils.DoNothingActor; @@ -79,7 +79,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { Assert.assertEquals("getPath", path, registerMsg.getPath()); Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances()); - reply(new RegisterDataTreeChangeListenerReply(getRef())); + reply(new RegisterDataTreeNotificationListenerReply(getRef())); for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) { Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); @@ -270,7 +270,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { Answer> answer = invocation -> { proxy.close(); - return Futures.successful((Object) new RegisterDataTreeChangeListenerReply(getRef())); + return Futures.successful((Object) new RegisterDataTreeNotificationListenerReply(getRef())); }; doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java index 1426e4a243..c8adf06dcf 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java @@ -36,7 +36,7 @@ import org.junit.Test; import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistration; import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistrationReply; import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener; -import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListenerReply; +import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply; import org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -161,7 +161,7 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest { ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, TestModel.TEST_PATH)); try { - RegisterDataTreeChangeListenerReply reply = (RegisterDataTreeChangeListenerReply) + RegisterDataTreeNotificationListenerReply reply = (RegisterDataTreeNotificationListenerReply) Await.result(Patterns.ask(shardActor, new RegisterDataTreeChangeListener(path, dclActor, false), new Timeout(5, TimeUnit.SECONDS)), Duration.create(5, TimeUnit.SECONDS)); return new SimpleEntry<>(listener, getSystem().actorSelection(reply.getListenerRegistrationPath())); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java index 0bd34aac3e..ce2a43f015 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java @@ -71,9 +71,8 @@ import org.opendaylight.controller.cluster.datastore.messages.ReadDataReply; import org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction; import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener; -import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply; import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener; -import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListenerReply; +import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply; import org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged; import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext; import org.opendaylight.controller.cluster.datastore.modification.MergeModification; @@ -148,8 +147,8 @@ public class ShardTest extends AbstractShardTest { shard.tell(new RegisterChangeListener(TestModel.TEST_PATH, dclActor, AsyncDataBroker.DataChangeScope.BASE, true), getRef()); - final RegisterChangeListenerReply reply = expectMsgClass(duration("3 seconds"), - RegisterChangeListenerReply.class); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("3 seconds"), + RegisterDataTreeNotificationListenerReply.class); final String replyPath = reply.getListenerRegistrationPath().toString(); assertTrue("Incorrect reply path: " + replyPath, replyPath.matches("akka:\\/\\/test\\/user\\/testRegisterChangeListener\\/\\$.*")); @@ -238,8 +237,8 @@ public class ShardTest extends AbstractShardTest { shard.tell(new RegisterChangeListener(path, dclActor, AsyncDataBroker.DataChangeScope.SUBTREE, false), getRef()); - final RegisterChangeListenerReply reply = expectMsgClass(duration("5 seconds"), - RegisterChangeListenerReply.class); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), + RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); // Sanity check - verify the shard is not the leader yet. @@ -278,8 +277,8 @@ public class ShardTest extends AbstractShardTest { shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, false), getRef()); - final RegisterDataTreeChangeListenerReply reply = expectMsgClass(duration("3 seconds"), - RegisterDataTreeChangeListenerReply.class); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("3 seconds"), + RegisterDataTreeNotificationListenerReply.class); final String replyPath = reply.getListenerRegistrationPath().toString(); assertTrue("Incorrect reply path: " + replyPath, replyPath.matches("akka:\\/\\/test\\/user\\/testRegisterDataTreeChangeListener\\/\\$.*")); @@ -342,8 +341,8 @@ public class ShardTest extends AbstractShardTest { assertEquals("Got first ElectionTimeout", true, onFirstElectionTimeout.await(5, TimeUnit.SECONDS)); shard.tell(new RegisterDataTreeChangeListener(path, dclActor, false), getRef()); - final RegisterDataTreeChangeListenerReply reply = expectMsgClass(duration("5 seconds"), - RegisterDataTreeChangeListenerReply.class); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), + RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistratioznPath", reply.getListenerRegistrationPath()); shard.tell(FindLeader.INSTANCE, getRef()); @@ -2146,8 +2145,8 @@ public class ShardTest extends AbstractShardTest { shard.tell(new RegisterChangeListener(path, dclActor, AsyncDataBroker.DataChangeScope.BASE, true), getRef()); - final RegisterChangeListenerReply reply = expectMsgClass(duration("5 seconds"), - RegisterChangeListenerReply.class); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), + RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); shard.tell(DatastoreContext.newBuilderFrom(dataStoreContextBuilder.build()) @@ -2196,9 +2195,9 @@ public class ShardTest extends AbstractShardTest { followerShard.tell( new RegisterChangeListener(path, dclActor, AsyncDataBroker.DataChangeScope.BASE, true), getRef()); - final RegisterChangeListenerReply reply = expectMsgClass(duration("5 seconds"), - RegisterChangeListenerReply.class); - assertNotNull("getListenerRegistratioznPath", reply.getListenerRegistrationPath()); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), + RegisterDataTreeNotificationListenerReply.class); + assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); writeToStore(followerShard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); @@ -2228,8 +2227,8 @@ public class ShardTest extends AbstractShardTest { waitUntilNoLeader(shard); shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), getRef()); - final RegisterDataTreeChangeListenerReply reply = expectMsgClass(duration("5 seconds"), - RegisterDataTreeChangeListenerReply.class); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), + RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); shard.tell(DatastoreContext.newBuilderFrom(dataStoreContextBuilder.build()) @@ -2261,8 +2260,8 @@ public class ShardTest extends AbstractShardTest { waitUntilNoLeader(shard); shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), getRef()); - final RegisterDataTreeChangeListenerReply reply = expectMsgClass(duration("5 seconds"), - RegisterDataTreeChangeListenerReply.class); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), + RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); final ActorSelection regActor = getSystem().actorSelection(reply.getListenerRegistrationPath()); @@ -2313,8 +2312,8 @@ public class ShardTest extends AbstractShardTest { actorFactory.generateActorId(testName + "-DataTreeChangeListener")); followerShard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), getRef()); - final RegisterDataTreeChangeListenerReply reply = expectMsgClass(duration("5 seconds"), - RegisterDataTreeChangeListenerReply.class); + final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), + RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); writeToStore(followerShard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); -- 2.36.6