Fix CS warnings in sal-clustering-commons and enable enforcement
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / AbstractUntypedActor.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.common.actor;
10
11 import akka.actor.ActorRef;
12 import akka.actor.UntypedActor;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 public abstract class AbstractUntypedActor extends UntypedActor {
17     // The member name should be lower case but it's referenced in many subclasses. Suppressing the CS warning for now.
18     @SuppressWarnings("checkstyle:MemberName")
19     protected final Logger LOG = LoggerFactory.getLogger(getClass());
20
21     protected AbstractUntypedActor() {
22         LOG.debug("Actor created {}", getSelf());
23         getContext().system().actorSelection("user/termination-monitor").tell(new Monitor(getSelf()), getSelf());
24     }
25
26     @Override
27     public final void onReceive(Object message) throws Exception {
28         handleReceive(message);
29     }
30
31     /**
32      * Receive and handle an incoming message. If the implementation does not handle this particular message,
33      * it should call {@link #ignoreMessage(Object)} or {@link #unknownMessage(Object)}.
34      *
35      * @param message the incoming message
36      * @throws Exception on message failure
37      */
38     protected abstract void handleReceive(Object message) throws Exception;
39
40     protected final void ignoreMessage(Object message) {
41         LOG.debug("Ignoring unhandled message {}", message);
42     }
43
44     protected final void unknownMessage(Object message) {
45         LOG.debug("Received unhandled message {}", message);
46         unhandled(message);
47     }
48
49     protected boolean isValidSender(ActorRef sender) {
50         // If the caller passes in a null sender (ActorRef.noSender()), akka translates that to the
51         // deadLetters actor.
52         return sender != null && !getContext().system().deadLetters().equals(sender);
53     }
54 }