Do not allow overrides of onReceive{Command,Recover} 92/36292/3
authorRobert Varga <rovarga@cisco.com>
Wed, 16 Mar 2016 13:21:16 +0000 (14:21 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 21 Mar 2016 11:11:42 +0000 (11:11 +0000)
We already have protected methods to handle these cases, do not allow
overrides, as they create confusion around which method does what.

Change-Id: I3d6e9b9c4dc72a53471bf60324e4c7f36845ed5b
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedPersistentActor.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java

index 9b7c2e8d4b0f3af9d522a55616d86a82f72a9cda..0a099885e4df083d5f2dff95faf5882de0b7a23c 100644 (file)
@@ -57,7 +57,8 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort,
         return Props.create(ExampleActor.class, id, peerAddresses, configParams);
     }
 
         return Props.create(ExampleActor.class, id, peerAddresses, configParams);
     }
 
-    @Override public void onReceiveCommand(Object message) throws Exception{
+    @Override
+    protected void handleCommand(Object message) {
         if(message instanceof KeyValue){
             if(isLeader()) {
                 String persistId = Long.toString(persistIdentifier++);
         if(message instanceof KeyValue){
             if(isLeader()) {
                 String persistId = Long.toString(persistIdentifier++);
@@ -89,7 +90,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort,
             }
 
         } else {
             }
 
         } else {
-            super.onReceiveCommand(message);
+            super.handleCommand(message);
         }
     }
 
         }
     }
 
@@ -145,7 +146,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort,
         }
     }
 
         }
     }
 
-    private ByteString fromObject(Object snapshot) throws Exception {
+    private static ByteString fromObject(Object snapshot) throws Exception {
         ByteArrayOutputStream b = null;
         ObjectOutputStream o = null;
         try {
         ByteArrayOutputStream b = null;
         ObjectOutputStream o = null;
         try {
@@ -165,7 +166,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort,
         }
     }
 
         }
     }
 
-    private Object toObject(byte [] bs) throws ClassNotFoundException, IOException {
+    private static Object toObject(byte [] bs) throws ClassNotFoundException, IOException {
         Object obj = null;
         ByteArrayInputStream bis = null;
         ObjectInputStream ois = null;
         Object obj = null;
         ByteArrayInputStream bis = null;
         ObjectInputStream ois = null;
@@ -188,10 +189,6 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort,
 
     }
 
 
     }
 
-    @Override public void onReceiveRecover(Object message)throws Exception {
-        super.onReceiveRecover(message);
-    }
-
     @Override public String persistenceId() {
         return getId();
     }
     @Override public String persistenceId() {
         return getId();
     }
index 92b3ff80ace9c426dcccc4f388053f10015abb63..90b16b8f1ec172bcc02ff213873983443139b482 100644 (file)
@@ -170,7 +170,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     }
 
     @Override
     }
 
     @Override
-    public void handleRecover(Object message) {
+    protected void handleRecover(Object message) {
         if(raftRecovery == null) {
             raftRecovery = newRaftActorRecoverySupport();
         }
         if(raftRecovery == null) {
             raftRecovery = newRaftActorRecoverySupport();
         }
@@ -207,7 +207,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     }
 
     @Override
     }
 
     @Override
-    public void handleCommand(final Object message) {
+    protected void handleCommand(final Object message) {
         if(serverConfigurationSupport.handleMessage(message, getSender())) {
             return;
         } else if (message instanceof ApplyState){
         if(serverConfigurationSupport.handleMessage(message, getSender())) {
             return;
         } else if (message instanceof ApplyState){
index c1a87e8c7b283e1f83b9114471dba911426127cb..c96ab9a245d5d0cb40cb2bbfb4fd83bbab1c744b 100644 (file)
@@ -206,7 +206,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
     }
 
     @Override
     }
 
     @Override
-    public void handleCommand(final Object message) {
+    protected void handleCommand(final Object message) {
         if(message instanceof RaftActorBehavior) {
             super.changeCurrentBehavior((RaftActorBehavior)message);
         } else {
         if(message instanceof RaftActorBehavior) {
             super.changeCurrentBehavior((RaftActorBehavior)message);
         } else {
index a48e8cd4e32904cc18bae74a67b39685db3394f3..e378fdc561fa2aedbff1d7e9719c424bec9a08e1 100644 (file)
@@ -22,7 +22,7 @@ public abstract class AbstractUntypedPersistentActor extends UntypedPersistentAc
     }
 
     @Override
     }
 
     @Override
-    public void onReceiveCommand(Object message) throws Exception {
+    public final void onReceiveCommand(Object message) throws Exception {
         final String messageType = message.getClass().getSimpleName();
         LOG.trace("Received message {}", messageType);
 
         final String messageType = message.getClass().getSimpleName();
         LOG.trace("Received message {}", messageType);
 
@@ -32,7 +32,7 @@ public abstract class AbstractUntypedPersistentActor extends UntypedPersistentAc
     }
 
     @Override
     }
 
     @Override
-    public void onReceiveRecover(Object message) throws Exception {
+    public final void onReceiveRecover(Object message) throws Exception {
         final String messageType = message.getClass().getSimpleName();
         LOG.trace("Received message {}", messageType);
         handleRecover(message);
         final String messageType = message.getClass().getSimpleName();
         LOG.trace("Received message {}", messageType);
         handleRecover(message);
index 138b71c10e111969c59777eedffce7c384f5afdd..fdf00c6fff9f20f8eb349ea108d3f97d1d642235 100644 (file)
@@ -196,18 +196,18 @@ public class Shard extends RaftActor {
     }
 
     @Override
     }
 
     @Override
-    public void onReceiveRecover(final Object message) throws Exception {
+    protected void handleRecover(final Object message) {
         LOG.debug("{}: onReceiveRecover: Received message {} from {}", persistenceId(), message.getClass(),
             getSender());
 
         LOG.debug("{}: onReceiveRecover: Received message {} from {}", persistenceId(), message.getClass(),
             getSender());
 
-        super.onReceiveRecover(message);
+        super.handleRecover(message);
         if (LOG.isTraceEnabled()) {
             appendEntriesReplyTracker.begin();
         }
     }
 
     @Override
         if (LOG.isTraceEnabled()) {
             appendEntriesReplyTracker.begin();
         }
     }
 
     @Override
-    public void onReceiveCommand(final Object message) throws Exception {
+    protected void handleCommand(final Object message) {
 
         MessageTracker.Context context = appendEntriesReplyTracker.received(message);
 
 
         MessageTracker.Context context = appendEntriesReplyTracker.received(message);
 
@@ -261,7 +261,7 @@ public class Shard extends RaftActor {
             } else if(ShardTransactionMessageRetrySupport.TIMER_MESSAGE_CLASS.isInstance(message)) {
                 messageRetrySupport.onTimerMessage(message);
             } else {
             } else if(ShardTransactionMessageRetrySupport.TIMER_MESSAGE_CLASS.isInstance(message)) {
                 messageRetrySupport.onTimerMessage(message);
             } else {
-                super.onReceiveCommand(message);
+                super.handleCommand(message);
             }
         } finally {
             context.done();
             }
         } finally {
             context.done();
index 2af106980f5041bba4ca93eabdf40451d5d089a3..76a6ac1e8f61beaf362b3851412e612a7cc4d0f8 100644 (file)
@@ -113,7 +113,7 @@ class EntityOwnershipShard extends Shard {
     }
 
     @Override
     }
 
     @Override
-    public void onReceiveCommand(final Object message) throws Exception {
+    public void handleCommand(final Object message) {
         if(message instanceof RegisterCandidateLocal) {
             onRegisterCandidateLocal((RegisterCandidateLocal) message);
         } else if(message instanceof UnregisterCandidateLocal) {
         if(message instanceof RegisterCandidateLocal) {
             onRegisterCandidateLocal((RegisterCandidateLocal) message);
         } else if(message instanceof UnregisterCandidateLocal) {
@@ -133,7 +133,7 @@ class EntityOwnershipShard extends Shard {
         } else if(message instanceof SelectOwner) {
             onSelectOwner((SelectOwner) message);
         } else if(!commitCoordinator.handleMessage(message, this)) {
         } else if(message instanceof SelectOwner) {
             onSelectOwner((SelectOwner) message);
         } else if(!commitCoordinator.handleMessage(message, this)) {
-            super.onReceiveCommand(message);
+            super.handleCommand(message);
         }
     }
 
         }
     }
 
index 7476ee2802706818b0237836625266ffcfa2efcd..bb80b2c273d859051a5db1b959bbf63830fa80b2 100644 (file)
@@ -1992,7 +1992,7 @@ public class ShardManagerTest extends AbstractActorTest {
         }
 
         @Override
         }
 
         @Override
-        public void handleRecover(Object message) throws Exception {
+        protected void handleRecover(Object message) throws Exception {
             try {
                 super.handleRecover(message);
             } finally {
             try {
                 super.handleRecover(message);
             } finally {
index 9fd33b217d9825e02bc4dbb1cc83edbc286afbfe..f639c8db49c659921f1f472284eb8812ad95b485 100644 (file)
@@ -174,7 +174,7 @@ public class ShardTest extends AbstractShardTest {
                     // it does do a persist)
                     return new Shard(newShardBuilder()) {
                         @Override
                     // it does do a persist)
                     return new Shard(newShardBuilder()) {
                         @Override
-                        public void onReceiveCommand(final Object message) throws Exception {
+                        public void handleCommand(final Object message) {
                             if(message instanceof ElectionTimeout && firstElectionTimeout) {
                                 // Got the first ElectionTimeout. We don't forward it to the
                                 // base Shard yet until we've sent the RegisterChangeListener
                             if(message instanceof ElectionTimeout && firstElectionTimeout) {
                                 // Got the first ElectionTimeout. We don't forward it to the
                                 // base Shard yet until we've sent the RegisterChangeListener
@@ -197,7 +197,7 @@ public class ShardTest extends AbstractShardTest {
 
                                 onFirstElectionTimeout.countDown();
                             } else {
 
                                 onFirstElectionTimeout.countDown();
                             } else {
-                                super.onReceiveCommand(message);
+                                super.handleCommand(message);
                             }
                         }
                     };
                             }
                         }
                     };
@@ -286,7 +286,7 @@ public class ShardTest extends AbstractShardTest {
                 public Shard create() throws Exception {
                     return new Shard(newShardBuilder()) {
                         @Override
                 public Shard create() throws Exception {
                     return new Shard(newShardBuilder()) {
                         @Override
-                        public void onReceiveCommand(final Object message) throws Exception {
+                        public void handleCommand(final Object message) {
                             if(message instanceof ElectionTimeout && firstElectionTimeout) {
                                 firstElectionTimeout = false;
                                 final ActorRef self = getSelf();
                             if(message instanceof ElectionTimeout && firstElectionTimeout) {
                                 firstElectionTimeout = false;
                                 final ActorRef self = getSelf();
@@ -301,7 +301,7 @@ public class ShardTest extends AbstractShardTest {
 
                                 onFirstElectionTimeout.countDown();
                             } else {
 
                                 onFirstElectionTimeout.countDown();
                             } else {
-                                super.onReceiveCommand(message);
+                                super.handleCommand(message);
                             }
                         }
                     };
                             }
                         }
                     };
@@ -2011,8 +2011,8 @@ public class ShardTest extends AbstractShardTest {
                 public Shard create() throws Exception {
                     return new Shard(newShardBuilder()) {
                         @Override
                 public Shard create() throws Exception {
                     return new Shard(newShardBuilder()) {
                         @Override
-                        public void onReceiveCommand(final Object message) throws Exception {
-                            super.onReceiveCommand(message);
+                        public void handleCommand(final Object message) {
+                            super.handleCommand(message);
                             if(message.equals(TX_COMMIT_TIMEOUT_CHECK_MESSAGE)) {
                                 if(cleaupCheckLatch.get() != null) {
                                     cleaupCheckLatch.get().countDown();
                             if(message.equals(TX_COMMIT_TIMEOUT_CHECK_MESSAGE)) {
                                 if(cleaupCheckLatch.get() != null) {
                                     cleaupCheckLatch.get().countDown();
index d95f559a694b53be4f0cbb0c32303d8fc9632c01..e9d837c17ff1e41263e1b839d881cc30dcb554a8 100644 (file)
@@ -320,12 +320,12 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh
         }
 
         @Override
         }
 
         @Override
-        public void onReceiveCommand(final Object message) throws Exception {
+        public void handleCommand(final Object message) {
             try {
                 if(dataTree.get() != null && message instanceof GetShardDataTree) {
                     sender().tell(dataTree.get(), self());
                 } else {
             try {
                 if(dataTree.get() != null && message instanceof GetShardDataTree) {
                     sender().tell(dataTree.get(), self());
                 } else {
-                    super.onReceiveCommand(message);
+                    super.handleCommand(message);
                 }
             } finally {
                 Class<?> expMsgClass = messageClass.get();
                 }
             } finally {
                 Class<?> expMsgClass = messageClass.get();
index 3a53e78200824373ba8970b9ae0b1604733fd0e7..5c822ab3b8d2ee5fd3084399dd53ea1bcb42334e 100644 (file)
@@ -12,9 +12,9 @@ import static org.mockito.AdditionalMatchers.or;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.candidatePath;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.candidatePath;
@@ -834,9 +834,9 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest {
         }
 
         @Override
         }
 
         @Override
-        public void onReceiveCommand(Object message) throws Exception {
+        public void handleCommand(Object message) {
             if(!(message instanceof ElectionTimeout)) {
             if(!(message instanceof ElectionTimeout)) {
-                super.onReceiveCommand(message);
+                super.handleCommand(message);
             }
         }
     }
             }
         }
     }