2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.common.actor;
11 import akka.actor.AbstractActor;
12 import akka.actor.ActorRef;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public abstract class AbstractUntypedActor extends AbstractActor implements ExecuteInSelfActor {
19 // The member name should be lower case but it's referenced in many subclasses. Suppressing the CS warning for now.
20 @SuppressWarnings("checkstyle:MemberName")
21 @SuppressFBWarnings(value = "SLF4J_LOGGER_SHOULD_BE_PRIVATE", justification = "Class identity is required")
22 protected final Logger LOG = LoggerFactory.getLogger(getClass());
24 @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Akka class design")
25 protected AbstractUntypedActor() {
26 LOG.debug("Actor created {}", getSelf());
27 getContext().system().actorSelection("user/termination-monitor").tell(new Monitor(getSelf()), getSelf());
31 public final void executeInSelf(@NonNull final Runnable runnable) {
32 final ExecuteInSelfMessage message = new ExecuteInSelfMessage(runnable);
33 self().tell(message, ActorRef.noSender());
37 public Receive createReceive() {
38 return receiveBuilder()
39 .match(ExecuteInSelfMessage.class, ExecuteInSelfMessage::run)
40 .matchAny(this::handleReceive)
45 * Receive and handle an incoming message. If the implementation does not handle this particular message,
46 * it should call {@link #ignoreMessage(Object)} or {@link #unknownMessage(Object)}.
48 * @param message the incoming message
50 protected abstract void handleReceive(Object message);
52 protected final void ignoreMessage(final Object message) {
53 LOG.debug("Ignoring unhandled message {}", message);
56 protected final void unknownMessage(final Object message) {
57 LOG.debug("Received unhandled message {}", message);
61 protected boolean isValidSender(final ActorRef sender) {
62 // If the caller passes in a null sender (ActorRef.noSender()), akka translates that to the
64 return sender != null && !getContext().system().deadLetters().equals(sender);