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 / AbstractUntypedPersistentActor.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.persistence.UntypedPersistentActor;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 public abstract class AbstractUntypedPersistentActor extends UntypedPersistentActor {
16
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 AbstractUntypedPersistentActor() {
22         LOG.trace("Actor created {}", getSelf());
23         getContext().system().actorSelection("user/termination-monitor").tell(new Monitor(getSelf()), getSelf());
24     }
25
26     @Override
27     public final void onReceiveCommand(Object message) throws Exception {
28         final String messageType = message.getClass().getSimpleName();
29         LOG.trace("Received message {}", messageType);
30
31         handleCommand(message);
32
33         LOG.trace("Done handling message {}", messageType);
34     }
35
36     @Override
37     public final void onReceiveRecover(Object message) throws Exception {
38         final String messageType = message.getClass().getSimpleName();
39         LOG.trace("Received message {}", messageType);
40         handleRecover(message);
41         LOG.trace("Done handling message {}", messageType);
42     }
43
44     protected abstract void handleRecover(Object message) throws Exception;
45
46     protected abstract void handleCommand(Object message) throws Exception;
47
48     protected void ignoreMessage(Object message) {
49         LOG.debug("Unhandled message {} ", message);
50     }
51
52     protected void unknownMessage(Object message) throws Exception {
53         LOG.debug("Received unhandled message {}", message);
54         unhandled(message);
55     }
56 }