X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fcommon%2Factor%2FAbstractUntypedPersistentActor.java;h=8bf657e134939dea8b9bb3284149ffd4e314bfdf;hp=36b2866210cadb84d9db0ab28c5a8137236254a7;hb=HEAD;hpb=32633beca367fea1db194d310e286b14acc0e6a6 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 36b2866210..8bf657e134 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 @@ -5,66 +5,60 @@ * 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.common.actor; -import akka.event.Logging; -import akka.event.LoggingAdapter; -import akka.persistence.UntypedPersistentActor; - -public abstract class AbstractUntypedPersistentActor extends UntypedPersistentActor { +import akka.actor.ActorRef; +import akka.persistence.AbstractPersistentActor; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.eclipse.jdt.annotation.NonNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - protected final LoggingAdapter LOG = - Logging.getLogger(getContext().system(), this); +// FIXME: override getContext(), getSelf() and others to be final to get rid of +// SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR violation +public abstract class AbstractUntypedPersistentActor extends AbstractPersistentActor implements ExecuteInSelfActor { - public AbstractUntypedPersistentActor() { - if(LOG.isDebugEnabled()) { - LOG.debug("Actor created {}", getSelf()); - } - getContext(). - system(). - actorSelection("user/termination-monitor"). - tell(new Monitor(getSelf()), getSelf()); + // The member name should be lower case but it's referenced in many subclasses. Suppressing the CS warning for now. + @SuppressWarnings("checkstyle:MemberName") + @SuppressFBWarnings("SLF4J_LOGGER_SHOULD_BE_PRIVATE") + protected final Logger LOG = LoggerFactory.getLogger(getClass()); + @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Akka class design") + protected AbstractUntypedPersistentActor() { + LOG.trace("Actor created {}", getSelf()); + getContext().system().actorSelection("user/termination-monitor").tell(new Monitor(getSelf()), getSelf()); } - - @Override public void onReceiveCommand(Object message) throws Exception { - final String messageType = message.getClass().getSimpleName(); - if(LOG.isDebugEnabled()) { - LOG.debug("Received message {}", messageType); - } - handleCommand(message); - if(LOG.isDebugEnabled()) { - LOG.debug("Done handling message {}", messageType); - } - + @Override + public final void executeInSelf(@NonNull final Runnable runnable) { + final ExecuteInSelfMessage message = new ExecuteInSelfMessage(runnable); + LOG.trace("Scheduling execution of {}", message); + self().tell(message, ActorRef.noSender()); } - @Override public void onReceiveRecover(Object message) throws Exception { - final String messageType = message.getClass().getSimpleName(); - if(LOG.isDebugEnabled()) { - LOG.debug("Received message {}", messageType); - } - handleRecover(message); - if(LOG.isDebugEnabled()) { - LOG.debug("Done handling message {}", messageType); - } + @Override + public final Receive createReceive() { + return receiveBuilder() + .match(ExecuteInSelfMessage.class, ExecuteInSelfMessage::run) + .matchAny(this::handleCommand) + .build(); + } + @Override + public final Receive createReceiveRecover() { + return receiveBuilder().matchAny(this::handleRecover).build(); } protected abstract void handleRecover(Object message) throws Exception; protected abstract void handleCommand(Object message) throws Exception; - protected void ignoreMessage(Object message) { + protected void ignoreMessage(final Object message) { LOG.debug("Unhandled message {} ", message); } - protected void unknownMessage(Object message) throws Exception { - if(LOG.isDebugEnabled()) { - LOG.debug("Received unhandled message {}", message); - } + protected void unknownMessage(final Object message) { + LOG.debug("Received unhandled message {}", message); unhandled(message); } }