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 9b7c2e8..0a09988 100644 (file)
@@ -57,7 +57,8 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort,
         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++);
@@ -89,7 +90,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort,
             }
 
         } 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 {
@@ -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;
@@ -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();
     }
index 92b3ff8..90b16b8 100644 (file)
@@ -170,7 +170,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     }
 
     @Override
-    public void handleRecover(Object message) {
+    protected void handleRecover(Object message) {
         if(raftRecovery == null) {
             raftRecovery = newRaftActorRecoverySupport();
         }
@@ -207,7 +207,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
     }
 
     @Override
-    public void handleCommand(final Object message) {
+    protected void handleCommand(final Object message) {
         if(serverConfigurationSupport.handleMessage(message, getSender())) {
             return;
         } else if (message instanceof ApplyState){
index c1a87e8..c96ab9a 100644 (file)
@@ -206,7 +206,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
     }
 
     @Override
-    public void handleCommand(final Object message) {
+    protected void handleCommand(final Object message) {
         if(message instanceof RaftActorBehavior) {
             super.changeCurrentBehavior((RaftActorBehavior)message);
         } else {
index a48e8cd..e378fdc 100644 (file)
@@ -22,7 +22,7 @@ public abstract class AbstractUntypedPersistentActor extends UntypedPersistentAc
     }
 
     @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);
 
@@ -32,7 +32,7 @@ public abstract class AbstractUntypedPersistentActor extends UntypedPersistentAc
     }
 
     @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);
index 138b71c..fdf00c6 100644 (file)
@@ -196,18 +196,18 @@ public class Shard extends RaftActor {
     }
 
     @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());
 
-        super.onReceiveRecover(message);
+        super.handleRecover(message);
         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);
 
@@ -261,7 +261,7 @@ public class Shard extends RaftActor {
             } else if(ShardTransactionMessageRetrySupport.TIMER_MESSAGE_CLASS.isInstance(message)) {
                 messageRetrySupport.onTimerMessage(message);
             } else {
-                super.onReceiveCommand(message);
+                super.handleCommand(message);
             }
         } finally {
             context.done();
index 2af1069..76a6ac1 100644 (file)
@@ -113,7 +113,7 @@ class EntityOwnershipShard extends Shard {
     }
 
     @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) {
@@ -133,7 +133,7 @@ class EntityOwnershipShard extends Shard {
         } else if(message instanceof SelectOwner) {
             onSelectOwner((SelectOwner) message);
         } else if(!commitCoordinator.handleMessage(message, this)) {
-            super.onReceiveCommand(message);
+            super.handleCommand(message);
         }
     }
 
index 7476ee2..bb80b2c 100644 (file)
@@ -1992,7 +1992,7 @@ public class ShardManagerTest extends AbstractActorTest {
         }
 
         @Override
-        public void handleRecover(Object message) throws Exception {
+        protected void handleRecover(Object message) throws Exception {
             try {
                 super.handleRecover(message);
             } finally {
index 9fd33b2..f639c8d 100644 (file)
@@ -174,7 +174,7 @@ public class ShardTest extends AbstractShardTest {
                     // 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
@@ -197,7 +197,7 @@ public class ShardTest extends AbstractShardTest {
 
                                 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 void onReceiveCommand(final Object message) throws Exception {
+                        public void handleCommand(final Object message) {
                             if(message instanceof ElectionTimeout && firstElectionTimeout) {
                                 firstElectionTimeout = false;
                                 final ActorRef self = getSelf();
@@ -301,7 +301,7 @@ public class ShardTest extends AbstractShardTest {
 
                                 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 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();
index d95f559..e9d837c 100644 (file)
@@ -320,12 +320,12 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh
         }
 
         @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 {
-                    super.onReceiveCommand(message);
+                    super.handleCommand(message);
                 }
             } finally {
                 Class<?> expMsgClass = messageClass.get();
index 3a53e78..5c822ab 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.Mockito.times;
 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;
@@ -834,9 +834,9 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest {
         }
 
         @Override
-        public void onReceiveCommand(Object message) throws Exception {
+        public void handleCommand(Object message) {
             if(!(message instanceof ElectionTimeout)) {
-                super.onReceiveCommand(message);
+                super.handleCommand(message);
             }
         }
     }