Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / AbstractUntypedPersistentActor.java
index e9aaa65453c4b14fc40de1451a668a3091699fa9..8bf657e134939dea8b9bb3284149ffd4e314bfdf 100644 (file)
@@ -5,21 +5,25 @@
  * 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.actor.ActorRef;
-import akka.persistence.UntypedPersistentActor;
+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;
 
-public abstract class AbstractUntypedPersistentActor extends UntypedPersistentActor implements ExecuteInSelfActor {
+// 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 {
 
     // 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());
@@ -33,26 +37,16 @@ public abstract class AbstractUntypedPersistentActor extends UntypedPersistentAc
     }
 
     @Override
-    public final void onReceiveCommand(final Object message) throws Exception {
-        final String messageType = message.getClass().getSimpleName();
-        LOG.trace("Received message {}", messageType);
-
-        if (message instanceof ExecuteInSelfMessage) {
-            LOG.trace("Executing {}", message);
-            ((ExecuteInSelfMessage) message).run();
-        } else {
-            handleCommand(message);
-        }
-
-        LOG.trace("Done handling message {}", messageType);
+    public final Receive createReceive() {
+        return receiveBuilder()
+                .match(ExecuteInSelfMessage.class, ExecuteInSelfMessage::run)
+                .matchAny(this::handleCommand)
+                .build();
     }
 
     @Override
-    public final void onReceiveRecover(final Object message) throws Exception {
-        final String messageType = message.getClass().getSimpleName();
-        LOG.trace("Received message {}", messageType);
-        handleRecover(message);
-        LOG.trace("Done handling message {}", messageType);
+    public final Receive createReceiveRecover() {
+        return receiveBuilder().matchAny(this::handleRecover).build();
     }
 
     protected abstract void handleRecover(Object message) throws Exception;