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 public abstract class AbstractUntypedPersistentActor extends AbstractPersistentActor implements ExecuteInSelfActor {
19 // The member name should be lower case but it's referenced in many subclasses. Suppressing the CS warning for now.
20 @SuppressFBWarnings("SLF4J_LOGGER_SHOULD_BE_PRIVATE")
21 @SuppressWarnings("checkstyle:MemberName")
22 protected final Logger LOG = LoggerFactory.getLogger(getClass());
24 protected AbstractUntypedPersistentActor() {
25 LOG.trace("Actor created {}", getSelf());
26 getContext().system().actorSelection("user/termination-monitor").tell(new Monitor(getSelf()), getSelf());
30 public final void executeInSelf(@NonNull final Runnable runnable) {
31 final ExecuteInSelfMessage message = new ExecuteInSelfMessage(runnable);
32 LOG.trace("Scheduling execution of {}", message);
33 self().tell(message, ActorRef.noSender());
37 public final Receive createReceive() {
38 return receiveBuilder()
39 .match(ExecuteInSelfMessage.class, ExecuteInSelfMessage::run)
40 .matchAny(this::handleCommand)
45 public final Receive createReceiveRecover() {
46 return receiveBuilder().matchAny(this::handleRecover).build();
49 protected abstract void handleRecover(Object message) throws Exception;
51 protected abstract void handleCommand(Object message) throws Exception;
53 protected void ignoreMessage(final Object message) {
54 LOG.debug("Unhandled message {} ", message);
57 protected void unknownMessage(final Object message) {
58 LOG.debug("Received unhandled message {}", message);