Rename ValueTypes to LithiumValue
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / AbstractUntypedActor.java
index ca303a5c12ee54749b1ddcbaf24e1cb4bf8f522b..6af52fbd04e2af4a60ce5865e46a0b51570347bd 100644 (file)
@@ -8,12 +8,17 @@
 
 package org.opendaylight.controller.cluster.common.actor;
 
+import akka.actor.AbstractActor;
 import akka.actor.ActorRef;
-import akka.actor.UntypedActor;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import org.eclipse.jdt.annotation.NonNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public abstract class AbstractUntypedActor extends UntypedActor {
+public abstract class AbstractUntypedActor extends AbstractActor implements ExecuteInSelfActor {
+    // The member name should be lower case but it's referenced in many subclasses. Suppressing the CS warning for now.
+    @SuppressFBWarnings("SLF4J_LOGGER_SHOULD_BE_PRIVATE")
+    @SuppressWarnings("checkstyle:MemberName")
     protected final Logger LOG = LoggerFactory.getLogger(getClass());
 
     protected AbstractUntypedActor() {
@@ -22,29 +27,37 @@ public abstract class AbstractUntypedActor extends UntypedActor {
     }
 
     @Override
-    public final void onReceive(Object message) throws Exception {
-        handleReceive(message);
+    public final void executeInSelf(@NonNull final Runnable runnable) {
+        final ExecuteInSelfMessage message = new ExecuteInSelfMessage(runnable);
+        self().tell(message, ActorRef.noSender());
+    }
+
+    @Override
+    public Receive createReceive() {
+        return receiveBuilder()
+                .match(ExecuteInSelfMessage.class, ExecuteInSelfMessage::run)
+                .matchAny(this::handleReceive)
+                .build();
     }
 
     /**
      * Receive and handle an incoming message. If the implementation does not handle this particular message,
      * it should call {@link #ignoreMessage(Object)} or {@link #unknownMessage(Object)}.
      *
-     * @param message Incoming message
-     * @throws Exception
+     * @param message the incoming message
      */
-    protected abstract void handleReceive(Object message) throws Exception;
+    protected abstract void handleReceive(Object message);
 
-    protected final void ignoreMessage(Object message) {
+    protected final void ignoreMessage(final Object message) {
         LOG.debug("Ignoring unhandled message {}", message);
     }
 
-    protected final void unknownMessage(Object message) {
+    protected final void unknownMessage(final Object message) {
         LOG.debug("Received unhandled message {}", message);
         unhandled(message);
     }
 
-    protected boolean isValidSender(ActorRef sender) {
+    protected boolean isValidSender(final ActorRef sender) {
         // If the caller passes in a null sender (ActorRef.noSender()), akka translates that to the
         // deadLetters actor.
         return sender != null && !getContext().system().deadLetters().equals(sender);