From 15c366198fa48eefd94f4d1a72faa9833e988250 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 16 Mar 2016 14:21:16 +0100 Subject: [PATCH] Do not allow overrides of onReceive{Command,Recover} 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 --- .../controller/cluster/example/ExampleActor.java | 13 +++++-------- .../controller/cluster/raft/RaftActor.java | 4 ++-- .../controller/cluster/raft/MockRaftActor.java | 2 +- .../actor/AbstractUntypedPersistentActor.java | 4 ++-- .../controller/cluster/datastore/Shard.java | 8 ++++---- .../entityownership/EntityOwnershipShard.java | 4 ++-- .../cluster/datastore/ShardManagerTest.java | 2 +- .../controller/cluster/datastore/ShardTest.java | 12 ++++++------ .../DistributedEntityOwnershipServiceTest.java | 4 ++-- .../entityownership/EntityOwnershipShardTest.java | 6 +++--- 10 files changed, 28 insertions(+), 31 deletions(-) diff --git a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java index 9b7c2e8d4b..0a099885e4 100644 --- a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java +++ b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java @@ -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(); } diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java index 92b3ff80ac..90b16b8f1e 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java @@ -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){ diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java index c1a87e8c7b..c96ab9a245 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java @@ -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 { diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedPersistentActor.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedPersistentActor.java index a48e8cd4e3..e378fdc561 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedPersistentActor.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedPersistentActor.java @@ -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); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index 138b71c10e..fdf00c6fff 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -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(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java index 2af106980f..76a6ac1e8f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java @@ -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); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java index 7476ee2802..bb80b2c273 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java @@ -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 { 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 9fd33b217d..f639c8db49 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 @@ -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(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java index d95f559a69..e9d837c17f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java @@ -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(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java index 3a53e78200..5c822ab3b8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java @@ -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); } } } -- 2.36.6