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
8 package org.opendaylight.controller.cluster.common.actor;
10 import akka.actor.ActorRef;
11 import akka.persistence.AbstractPersistentActor;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 // FIXME: override getContext(), getSelf() and others to be final to get rid of
18 // SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR violation
19 public abstract class AbstractUntypedPersistentActor extends AbstractPersistentActor implements ExecuteInSelfActor {
21 // The member name should be lower case but it's referenced in many subclasses. Suppressing the CS warning for now.
22 @SuppressWarnings("checkstyle:MemberName")
23 @SuppressFBWarnings("SLF4J_LOGGER_SHOULD_BE_PRIVATE")
24 protected final Logger LOG = LoggerFactory.getLogger(getClass());
26 @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Akka class design")
27 protected AbstractUntypedPersistentActor() {
28 LOG.trace("Actor created {}", getSelf());
29 getContext().system().actorSelection("user/termination-monitor").tell(new Monitor(getSelf()), getSelf());
33 public final void executeInSelf(@NonNull final Runnable runnable) {
34 final ExecuteInSelfMessage message = new ExecuteInSelfMessage(runnable);
35 LOG.trace("Scheduling execution of {}", message);
36 self().tell(message, ActorRef.noSender());
40 public final Receive createReceive() {
41 return receiveBuilder()
42 .match(ExecuteInSelfMessage.class, ExecuteInSelfMessage::run)
43 .matchAny(this::handleCommand)
48 public final Receive createReceiveRecover() {
49 return receiveBuilder().matchAny(this::handleRecover).build();
52 protected abstract void handleRecover(Object message) throws Exception;
54 protected abstract void handleCommand(Object message) throws Exception;
56 protected void ignoreMessage(final Object message) {
57 LOG.debug("Unhandled message {} ", message);
60 protected void unknownMessage(final Object message) {
61 LOG.debug("Received unhandled message {}", message);