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.ActorRef;
12 import akka.actor.UntypedActor;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 public abstract class AbstractUntypedActor extends UntypedActor {
17 protected final Logger LOG = LoggerFactory.getLogger(getClass());
19 protected AbstractUntypedActor() {
20 LOG.debug("Actor created {}", getSelf());
21 getContext().system().actorSelection("user/termination-monitor").tell(new Monitor(getSelf()), getSelf());
25 public final void onReceive(Object message) throws Exception {
26 handleReceive(message);
30 * Receive and handle an incoming message. If the implementation does not handle this particular message,
31 * it should call {@link #ignoreMessage(Object)} or {@link #unknownMessage(Object)}.
33 * @param message Incoming message
36 protected abstract void handleReceive(Object message) throws Exception;
38 protected final void ignoreMessage(Object message) {
39 LOG.debug("Ignoring unhandled message {}", message);
42 protected final void unknownMessage(Object message) {
43 LOG.debug("Received unhandled message {}", message);
47 protected boolean isValidSender(ActorRef sender) {
48 // If the caller passes in a null sender (ActorRef.noSender()), akka translates that to the
50 return sender != null && !getContext().system().deadLetters().equals(sender);