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.event.Logging;
12 import akka.event.LoggingAdapter;
13 import akka.persistence.UntypedPersistentActor;
15 public abstract class AbstractUntypedPersistentActor extends UntypedPersistentActor {
17 protected final LoggingAdapter LOG =
18 Logging.getLogger(getContext().system(), this);
20 public AbstractUntypedPersistentActor() {
21 if(LOG.isDebugEnabled()) {
22 LOG.debug("Actor created {}", getSelf());
26 actorSelection("user/termination-monitor").
27 tell(new Monitor(getSelf()), getSelf());
32 @Override public void onReceiveCommand(Object message) throws Exception {
33 final String messageType = message.getClass().getSimpleName();
34 if(LOG.isDebugEnabled()) {
35 LOG.debug("Received message {}", messageType);
37 handleCommand(message);
38 if(LOG.isDebugEnabled()) {
39 LOG.debug("Done handling message {}", messageType);
44 @Override public void onReceiveRecover(Object message) throws Exception {
45 final String messageType = message.getClass().getSimpleName();
46 if(LOG.isDebugEnabled()) {
47 LOG.debug("Received message {}", messageType);
49 handleRecover(message);
50 if(LOG.isDebugEnabled()) {
51 LOG.debug("Done handling message {}", messageType);
56 protected abstract void handleRecover(Object message) throws Exception;
58 protected abstract void handleCommand(Object message) throws Exception;
60 protected void ignoreMessage(Object message) {
61 LOG.debug("Unhandled message {} ", message);
64 protected void unknownMessage(Object message) throws Exception {
65 if(LOG.isDebugEnabled()) {
66 LOG.debug("Received unhandled message {}", message);